How to hide column of DataGridView when using custom DataSource?

前端 未结 7 1731
时光取名叫无心
时光取名叫无心 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:19

    I had the same problem

    Here is the Solution that might work for you. It worked for me

        GridView1.DataBind();
    if (GridView1.Columns.Count > 0)
        GridView1.Columns[0].Visible = false;
    else
    {
        GridView1.HeaderRow.Cells[0].Visible = false;
        foreach (GridViewRow gvr in GridView1.Rows)
        {
            gvr.Cells[0].Visible = false;
        }
    }
    

提交回复
热议问题