I don't want to loop through all the columns and set each column's Visible to false. I wonder if there is a quick way to do so.
Thank you!
I don't want to loop through all the columns and set each column's Visible to false. I wonder if there is a quick way to do so.
Thank you!
Also you can use LINQ as below:
dataGridView1.Columns.OfType<DataGridViewColumn>().ToList().ForEach(col => col.Visible = false);
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
for (int i = 0; i < dataGridView.Columns.Count; i++)
{
dataGridView.Columns[i].Visible = false;
}
set data source to null, when you want to show it again, you can set the data source back.
Or you can set Gridview visible false or gridview containing control to visible false.
Have two grids the same exact size and location.
if(conditionMet)
{
grid1.visible = false;
grid2.visible = true;
}
Old Question thought it might be helpful for someone !! This might be an easy option..
foreach (DataGridViewColumn col in myDgv.Columns)
{
col.Visible = false;
}
as well as you can iterate through rows..
foreach (DataGridViewRow row in myDgv.Rows)
{
// your code
}