How to hide column of DataGridView when using custom DataSource?

前端 未结 7 1667
时光取名叫无心
时光取名叫无心 2020-12-08 20:07

I have a small app in c#, it has a DataGridView that gets filled using:

grid.DataSource = MyDatasource array;

MyClass hold the structure for the

7条回答
  •  抹茶落季
    2020-12-08 20:10

    I"m not sure if its too late, but the problem is that, you cannot set the columns in design mode if you are binding at runtime. So if you are binding at runtime, go ahead and remove the columns from the design mode and do it pragmatically

    ex..

         if (dt.Rows.Count > 0)
        {
            dataGridViewProjects.DataSource = dt;
            dataGridViewProjects.Columns["Title"].Width = 300;
            dataGridViewProjects.Columns["ID"].Visible = false;
        }
    

提交回复
热议问题