Reputation: 63317
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!
Upvotes: 3
Views: 8899
Reputation: 3469
Also you can use LINQ as below:
dataGridView1.Columns.OfType<DataGridViewColumn>().ToList().ForEach(col => col.Visible = false);
Upvotes: 6
Reputation: 5386
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
}
Upvotes: 0
Reputation: 21
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
for (int i = 0; i < dataGridView.Columns.Count; i++)
{
dataGridView.Columns[i].Visible = false;
}
Upvotes: 2
Reputation: 11
Have two grids the same exact size and location.
if(conditionMet)
{
grid1.visible = false;
grid2.visible = true;
}
Upvotes: 0
Reputation: 63065
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.
Upvotes: 0