jssong2000
asked on
Set DataGridViewCheckBoxColumn default Value
Hi expert,
I try to use DataGridView in a winform app. I added DataGridViewCheckBoxColumn .
I'd like to set all checkbox default value as false.
I use the DefaultValuesNeeded event but not working.
Then I try to use a loop. It worked. But It's very slow.
It only changed 20-30 rows in 10 seconds. There are thousands rows in the datagridview.
So the performance is not acceptable. Please help. Appreciated!!
Please check code from attachment.
expertexchange.txt
I try to use DataGridView in a winform app. I added DataGridViewCheckBoxColumn
I'd like to set all checkbox default value as false.
I use the DefaultValuesNeeded event but not working.
Then I try to use a loop. It worked. But It's very slow.
It only changed 20-30 rows in 10 seconds. There are thousands rows in the datagridview.
So the performance is not acceptable. Please help. Appreciated!!
Please check code from attachment.
expertexchange.txt
So is it defaulting to true currently?
ASKER
If I don't setup. The default value is null.
User has to click two times to make it checked. It's inconvenient.
User has to click two times to make it checked. It's inconvenient.
Add a column to the table first. This could be done at the SQL level with a Select such as this one:
SELECT False AS Col1, Field1, Field2,...
Or add it to the DataTable in memory If you cannot add it to the SQL for some reason.
If you cannot do either, then you might consider the fact that the DataGridView events are often tricky to work with. For instance, when you fill a DataGridView, the validating events are often triggered uselessly, because one can assume that the data was already verified before it was stores in the database that provides the DataTable.
You might thus look at the events that are triggered when by your code, and deactivate it before you run it:
this.dataGridView1.RowVali dating -= new System.Windows.Forms.DataG ridViewCel lCancelEve ntHandler( this.dataG ridView1_R owValidati ng);
this.dataGridView1.CellVal idating -= new System.Windows.Forms.DataG ridViewCel lValidatin gEventHand ler(this.d ataGridVie w1_CellVal idating);
...
Run your code without the events, then add them back so that they are ready to trigger when the user starts interacting with the grid:
this.dataGridView1.RowVali dating += new System.Windows.Forms.DataG ridViewCel lCancelEve ntHandler( this.dataG ridView1_R owValidati ng);
this.dataGridView1.CellVal idating += new System.Windows.Forms.DataG ridViewCel lValidatin gEventHand ler(this.d ataGridVie w1_CellVal idating);
SELECT False AS Col1, Field1, Field2,...
Or add it to the DataTable in memory If you cannot add it to the SQL for some reason.
If you cannot do either, then you might consider the fact that the DataGridView events are often tricky to work with. For instance, when you fill a DataGridView, the validating events are often triggered uselessly, because one can assume that the data was already verified before it was stores in the database that provides the DataTable.
You might thus look at the events that are triggered when by your code, and deactivate it before you run it:
this.dataGridView1.RowVali
this.dataGridView1.CellVal
...
Run your code without the events, then add them back so that they are ready to trigger when the user starts interacting with the grid:
this.dataGridView1.RowVali
this.dataGridView1.CellVal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a solution.