I'm trying to make a window forms application in which I need to hide and show rows of a datagridView quite frequently. Currently and using a loop
for (int i=0;i<grid.Rows.Count;i++){
grid.Rows[i].Visible = false;
}
But this is making my UI too slow, is there a faster way to do this?? Thanks in advance.
You can remove all rows after storing them in a list and add them back as needed:
List<DataGridViewRow> rows = null;
// prepare list
rows = new List<DataGridViewRow>();
// copy rows to list
rows.AddRange(dataGridView1.Rows.Cast<DataGridViewRow>());
// remove them all
dataGridView1.Rows.Clear();
// add them back:
dataGridView1.Rows.AddRange(rows.ToArray());
// clean up
rows.Clear();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With