开发者

How to change the committing value in dataGridView?

开发者 https://www.devze.com 2023-02-14 21:06 出处:网络
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.

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;
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消