This is what I’m currently using to implement a “Check all” feature on a bound DataGridView:
int max = ((DataTable)dataGridRes.DataSource).Rows.Count;
for (int i = 0; i < max; i++)
{
if(((DataTable)dataGridRes.DataSource).Rows[i].Field<long>(0) == 0)
((DataTable)dataGridRes.DataSource).Rows[i].SetField(0, 1);
}
However this code is hopelessly slow. On a 625 row DataTable it takes aprox 5 seconds to complete on my computer. Very unacceptable.
What am I doing wrong? What better way can I use to do bulk edits on a DataGridView?
I found a way to speed it up to an acceptable performance. Essentially unbind the control, do the update on the DataTable and rebind it.