Tavousi
Tavousi

Reputation: 15446

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 want to show column2 and then column1. How to I do this. Thanks.

Upvotes: 0

Views: 270

Answers (2)

Baharanji
Baharanji

Reputation: 218

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();

Upvotes: 0

Binil
Binil

Reputation: 6583

you can set the DisplayIndex of the Column

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

this will display the column as second column

Upvotes: 1

Related Questions