DataGridView Checkbox

C

Carolina

Hello,

Is there any way I could get an event like a CheckboxChanged for a checkbox
in the datagridview?

I tried to do this with the event CellContentClick but it happens just
before the value of the checkbox changes.

Thanks in advance,
 
M

mrstrong

Hello,

Is there any way I could get an event like a CheckboxChanged for a checkbox
in the datagridview?

I tried to do this with the event CellContentClick but it happens just
before the value of the checkbox changes.

Thanks in advance,

Gday Carolina,

I am having issues of my own with datagridviews and checkboxes at
present...

I dont know your situation and whether or not you actually do need to
capture the checkedchanged event when it actually happens...

What I do is have the checkboxes as unbound, and when the form loads
up or there is a datarefresh I will set the checkboxes based off the
appropriate values in my data. And when a save operation takes place
do the reverse - check the values of each checkbox and set the
appropriate value in the data to be saved out.

I dont know if this helps.

Let me know if you get any responses about your original question.

Thanks!

Peter
 
C

Carolina

Ey!!

Thanks Peter for your attention.

Well, It's been quite complicated this. What I actually need is everytime I
check on the checkbox, to do a validation (comparing the value of a column
between rows selected), and after that if the validation is correct then
leave the checkbox checked. If the validation is incorrect then uncheck the
checkbox.

I tried with the event CurrentCellDirtyStateChange, doing the commit of the
edition here everytime IsCurrentCellDirty is in false. But its being still
difficult getting back to the previous state, when the checkbox were
unchecked.

I even tried this code which is supposed to capture SelectedIndexChanged for
a combobox. Well I thought it would work if i adapted it to a CheckBox:
private void dataGridView1_EditingControlShowing(object sender,

DataGridViewEditingControlShowingEventArgs e)

{

CheckBox cb = e.Control as CheckBox;

if (cb != null)

{

cb.CheckedChanged-= new
EventHandler(cb_CheckedChanged);



cb.CheckedChanged+= new
EventHandler(cb_CheckedChanged);

}

}



void cb_CheckedChanged(object sender, EventArgs e)

{

MessageBox.Show("Selected index changed");
}



But nop, it didnt work well.



I don't really know what to do.





Thanks again,



Carolina
 
G

Greg Mulvihill

Check out this link, it helped me solve my similar issue.

http://www.ureader.com/message/33369892.aspx

Also, I had success with this:

private void dataGridView1(object sender, DataGridViewCellEventArgs e)
{
bool bSelected = (bool)dataGridView1["Selected",
e.RowIndex].EditedFormattedValue;

//...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top