Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagridview checkboxcolumn

Status
Not open for further replies.

VBmim

Programmer
Jun 25, 2001
361
BE
Hello All,

I have a datagridview with a checkboxcolumn (bound) in it. I would like to implement 'select all' and 'deselect all' functions, but what I have tried so far has been way too slow.

Code:
for (int i = 0; i < dgvItems.Rows.Count; i++)
    dgvItems.Rows[i].Cells["check_analyze"].Value = true;

This code takes almost two minutes for 400 rows. This is unacceptable!
The datagridview is bound to an xsd bindingsource, which I fill with a datatable.

What am I doing wrong...
Is there a way to set a certain value to a whole column for a datagridview, or for a datatable?

Greetz

VBMim
 
What about setting the underlying row data for that column, instead of setting it from the UI? You still need to iterate the rows though, but at the least the de-referencing overhead is a lot less ...
Code:
[COLOR=green]//Assuming dvsrc (a DataView) is dgvItems' datasource[/color]
for (int i = 0; i < dvsrc.Rows.Count; i++) {
    //dgvItems.Rows[i].Cells["check_analyze"].Value = true;
    dvsrc[i]["col_check_analyze"] = true;
}
Hope this helps
 
Hello phinoppix,

Thanks for your response.
I tested the code you suggested and it is a little bit better, but still unacceptable. Instead of 1:30 minutes, it takes only 1 minute.

I tried the following code:
Code:
dgvItems.SuspendLayout();
ItemBindingSource.SuspendBinding();
DataTable dt = (DataTable)ItemBindingSource.DataSource;
for (int i = 0; i < dt.Rows.Count; i++)
       dt.Rows[i]["check_analyze"] = false;
ItemBindingSource.ResumeBinding();
dgvItem.ResumeLayout();

Do you have other ideas?

Greetz,

VBMim
 
Hi,

I'm really wondering why your app is taking that long to update. Do you have an event handler that gets triggered everytime you update a row, eg. rowupdating? If you do, maybe you can check from there which algo is causing the bottleneck.

I tried setting up a datagridview, a dataset with a 2-column table (bool and string columns), then bind it with a bindingSource, and populated the table with 10,000 rows. The string column is set via an DataTable.ColumnChanging event handler and displays "true"/"false". it takes about 2-3 seconds only checking/unchecking all rows. My machine has quite plenty of processing power, but even on a minimum machine, it shouldn't take a minute to process all 400 or so rows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top