Wednesday, March 18, 2009 3:33 PMI have a checkbox column in my datagridview. But when I click the checkbox the cellContentClick event is raised. But when I try and see if that checkbox is checked it still says that it isn't until after the event finishes then I can see it's checked. How can I get around this issue?
Any help would be greatly appreciated.
Friday, March 20, 2009 12:20 PM
DataGridView.CellContentClick Event occurs when the content within a cell is clicked.
For clicks in a DataGridViewCheckBoxCell, this event occurs before the check box changes value, so if you do not want to calculate the expected value based on the current value, you will typically handle the DataGridView.CellValueChanged event instead. Because that event occurs only when the user-specified value is committed, which typically occurs when focus leaves the cell, you must also handle the DataGridView.CurrentCellDirtyStateChanged event. In that handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.
I don't very clearly know what is your purpose. So please follow up with necessary information if you still have problem. Thank you!
Friday, March 20, 2009 12:34 PMOne quick and dirty method is ending the editdgv.EndEdit();
Friday, March 20, 2009 1:03 PMGuo & Arjun,
Thank you both for your replies.
What i'm doing is when the user clicks the checkbox the DataGridView_CellContentClick event fires within that event I set focus on the DataGridView.
I did this so I can leave the clicked cell and have DataGridView_CellValueChanged fire. This is where I have most of my code.
Is this method ok or am I not doing it the proper way?
I might end up using a 3rd party control since the DataGridView refreshes so slow even with 50 rows of data. I even tested with populating the DataGridView with the numbers 1-50 and when I scroll it's choppy.
Thanks again guys
Monday, March 23, 2009 3:18 AMHi Jerry,
Thank you for you reply.
Have you resolved your problem? I'm sorry that I still don't very well understand your purpose. Would you mind providing more necessary information about your purpose if you still have problem? Please check the related events' links I have mentioned above.
Monday, March 23, 2009 1:16 PMGuo,
I haven't solved that problem yet. I'm trying to do it with a 3rd party control because the datagridview is very choppy when I scroll a list of a 100 and I can't have that when I release this. The 3rd party control does the onchange event as you mentioned above and it works fine.
The main purpose of this app was to allow the user to select from 3 different combo boxes. Based on the selections a datagridview is populated. When the user changes the value of a checkbox that specific rows data will populate or unpopulate a different datagridview and from there the user can click on another checkbox to populate a 3rd datagridview with more data.
There are a lot of ways this data changes and it's frustrating that the datagridview was slow and the re-painting when I scrolled was so bad. I even populated it with the numbers 1-100 and scrolled through it and it was still choppy.
If you can shed any light on that I would appreciate it just in case the 3rd party control doesn't work.
Thank you so much for you help it is appreciated.
Tuesday, March 24, 2009 3:09 AMHi Jerry,
Thank you for you response.
It should be to say that datagridview has no problem when scroll with only 100 records. The choppy problem as you mentioned may has something to do with your code populating the datagridview, so would you mind providing your sample code populating the datagridview if you use DataGridView Control.
Please consider posting your thread to third-party control related forums if you use them. Thank you for your understanding!
Tuesday, March 24, 2009 12:54 PMGuo,
The code at the bottom of this thread
Causes my grid to be choppy. That is how I populated it for my test and it was still slow to paint.
Sorry for the dup threads wasn't my intention.
Wednesday, March 25, 2009 3:07 AMHi Jerry,
Thank you for your response.
I have said in that thread, your sample code populating datagridview has no problem. The choppy problem may has something to do with other code in your project. Would you mind sending your project to my email, t-guosur at microsoft dot com. Or please consider posting your thread to Windows Forms Data Controls and Databinding Forum. You may get quicker and better responses there.
- Edited by Guo Surfer Wednesday, March 25, 2009 3:19 AM
Wednesday, March 25, 2009 3:17 AMHi Jerry,
We are marking the above posts as answers for your first question "Checkbox in datagridview CellContentClick event".
For your another question "datagridview choppy problem", I'm very sorry I can't figure out right now, please consider posting your thread to Windows Forms Data Controls and Databinding Forum. You may get quicker and better responses there.
Thank you very much for your understanding!
Wednesday, March 25, 2009 1:45 PMGuo,
Thank you for all your help.
That link you posted says "HTTP 403 Forbidden" is that the correct link?
Since you are busy I will just post my info there and not bother you with the project.
Here is the entire code for that form with the datagridview that is choppy.