Arrange Columns in a DataGridView

2020-08-09 09:52发布

I have a datagridview that is populated by a stored proc. Typically I would reorder the columns using the 'Edit Columns' dialog but this datagridview is being used to display data from different sources so I can't do that.

I have figured out how to rename the Headers and make certain columns Frozen but how do I change the display order on them?

3条回答
Evening l夕情丶
2楼-- · 2020-08-09 10:31
 grid.AllowUserToOrderColumns = true;
查看更多
Summer. ? 凉城
3楼-- · 2020-08-09 10:42

Can you set the DisplayIndex for the columns?

查看更多
劫难
4楼-- · 2020-08-09 10:48

With the DisplayIndex property

myGridView.Columns["myFirstCol"].DisplayIndex = 0;
myGridView.Columns["mySecondCol"].DisplayIndex = 1;
查看更多
登录 后发表回答