I have a dataGridView
that has a column with checkb开发者_如何学运维oxes. Whenever the user clicks on a checkbox I use the event CellContentClick
where I process the necessary action.
But now, in some cases, I would like the value not to be committed (the checkbox to be unchecked). Any idea how to do this?
You might want to look at the CellValidating event. So something like this:
void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
object new_value = e.FormattedValue;
// Do something
// If you dont like what you did, cancel the update
if(nope_didnt_like_it)
{
e.Cancel = true;
}
}
精彩评论