开发者

Change columns in datagrid

I work with a winform application. I want to change the place of two columns with eachother in a datagridview. For example I have a datagridview with two column that first column1 is showing and then column2 is showing.And now I wa开发者_如何学Gont to show column2 and then column1. How to I do this. Thanks.


you can set the DisplayIndex of the Column

dataGridView1.Columns["FirstColumnName"].DisplayIndex = 1;

this will display the column as second column


You can try to do something like this:

DataTable dt=new DataTable();
dt.Columns.Add("Column2");
dt.Columns.Add("Column1");
DataRow dr=dt.NewRow();
dr["Column2"]="";
dr["Column1"]="";
dt.Rows.Add(dr);
yourDatagrid.DataSource=dt;
YourDatagrid.DataBind();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜