Search code examples
c#winformsdatagridviewcolumn

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 this. Thanks.


Solution

  • 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.