Solved

Set DataGridViewCheckBoxColumn default Value

Posted on 2014-02-14
5
2,750 Views
Last Modified: 2014-02-19
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
0
Comment
Question by:jssong2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39859379
So is it defaulting to true currently?
0
 

Author Comment

by:jssong2000
ID: 39859423
If I don't setup. The default value is null.
User has to click two times to make it checked. It's inconvenient.
0
 
LVL 40
ID: 39859543
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.RowValidating -= new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_RowValidating);
this.dataGridView1.CellValidating -= new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView1_CellValidating);
...

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.RowValidating += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_RowValidating);
this.dataGridView1.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView1_CellValidating);
0
 

Accepted Solution

by:
jssong2000 earned 0 total points
ID: 39859615
I found a solution:

checkColumn.ThreeState = false;
0
 

Author Closing Comment

by:jssong2000
ID: 39869814
I found a solution.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question