开发者

add a column between two columns of a gridview

I used a datagridview in my winform application. I load datagrid with a dataset that have 4 columns. Next I want to add a column between column2 & column3. How to I do th开发者_JAVA百科is. Thanks.


You can use Insert method on DataGridView.Columns collection. For example,

var column = new DataGridViewTextBoxColumn();
// initialize column properties
...
myGridView.Columns.Insert(2, column);

Preferably, this should happen after the data binding.


Using the Visual Studio Designer, you can simply add columns of every kind in the options of the DGV.

You can even set the position of the columns by drag&drop.

If you can't or don't want to use the Designer VinayC told you to do it the code-way.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜