Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting the checkbox state from a checkboxcolumn in datagridview

Posted on 2007-10-15
9
Medium Priority
?
2,151 Views
Last Modified: 2012-05-05
Hi,
I've built a databound checkbox column  as follows.

DataGridViewCheckBoxColumn checkboxColumn = new DataGridViewCheckBoxColumn();
checkboxColumn.HeaderText = "P/Work Received";
checkboxColumn.Name = "chkPaperwork_Received";
checkboxColumn.DataPropertyName = "chkPaperworkReceived";
checkboxColumn.TrueValue = "Y";
checkboxColumn.FalseValue = "N";
checkboxColumn.Width = 60;
idx = dgvNbmu.Columns.Add(checkboxColumn);

When a checkbox on a row is clicked, I capture the event and try to process it as follows:
CheckBox cb = new CheckBox();
cb.Checked = (bool)dgvNbmu.Rows[e.RowIndex].Cells["chkPaperwork_Received"].Value;

The problem is that the dgvNbmu.Rows[e.RowIndex].Cells["chkPaperwork_Received"].Value is still "Y", which is the original value.
As the checkbox was already checked, I am expecting to get a false value from somewhere.

Am I looking in the wrong place, if so, where should I be getting the latest value of the checkbox from ?
thanks,
Graham

0
Comment
Question by:graham_ball
  • 4
  • 4
9 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20077187
On what exact "event" have you written this code ?
0
 

Author Comment

by:graham_ball
ID: 20077266

private void dgvNbmu_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dgvNbmu.Columns[e.ColumnIndex].Name == "chkPaperwork_Received")
      {
      Process_PaperworkReceived(e);
      }
}
0
 
LVL 22

Expert Comment

by:p_davis
ID: 20077519
it looks to me like you are processing the cell being clicked not the check box.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:graham_ball
ID: 20077528
So, how do you process the checkbox?
0
 
LVL 22

Accepted Solution

by:
p_davis earned 500 total points
ID: 20077693
this msdn article explains what is happening and gives some solutions

http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn(VS.80).aspx
0
 
LVL 22

Expert Comment

by:p_davis
ID: 20077700
let me know if you need help with it further.
0
 

Author Comment

by:graham_ball
ID: 20078075
That works OK - what a palava for something ostensibly simple (par for the course, I suppose).
Thanks, don't know how I missed that.
Just one thing, I'm sure that earlier, when it wasn't working, when I clicked the checkbox, the cell background did not get selected. Now it does and turns blue until the grid is refreshed.
Is there any way of stopping that?
Thanks Graham
0
 
LVL 22

Expert Comment

by:p_davis
ID: 20078196
i'm not aware of any property, but that doesn't mean that it doesn't exist. my familiarity with windows controls is waning since we moved to some 3rd party controls but their should be an event that catches the cells backgroundcolorchanged.

more fudgery.....
0
 

Author Comment

by:graham_ball
ID: 20078230
Ok - thanks.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 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