views:

383

answers:

3

I'm trying to figure out some behavior in an app that I'm supporting. The snippet is:

foreach (DataGridViewRow pGridRow in grdEmail.Rows)
{
    pGridRow.Cells[0].Value = chkSelectAll.Checked;
    pCount = pGridRow.Index + 1;
}

Which is essentially trying to select all rows in a grid (check a box) when a select all checkbox is clicked.

When the grid has a few rows (hundred or so) it works beautifully. However, when I have around 5000 rows in it, this thing crawls. The pGridRow.Cells[0].Value = chkSelectAll.Checked command takes a second or so (timed by putting Console.prints above and below it).

Any idea would be appreciated in resolving this.

A: 

What is the point of having 5000 rows visible at once?

Can't this be paginated?
Can't the checkbox be sent as checked by default?

shahkalpesh
There's plenty of reasons to show 5000 rows at once. Sorting for one. 5000 isn't actually that much. I have users who would panic if they couldn't see all the data at once.
IainMH
A: 

Hi,

Try modifying the underlying datasource (if any) directly instead of setting the value of the cell.

//assuming datasetFoo.Tables(0) is the DataSource of the DataGridView
foreach (DataRow rowFoo in datasetFoo.Tables(0) { 
        rowFoo ("Sel") = chkSelectAll.Checked; 
    }
+1  A: 

Showing thousands of rows at once is wasteful and makes it very difficult for users to find the data they need. I would definitely recommend pagination. Your users will thank you. (Unless they have specifically requested to see 5000 at once, which seems silly.)

Gary the Llama