How to detect DataGridView CheckBox event change?

后端 未结 16 2455
离开以前
离开以前 2020-11-27 12:43

I have a winforms app and want to trigger some code when a checkbox embedded in a DataGridView control is checked / unchecked. Every event I have tried either

16条回答
  •  青春惊慌失措
    2020-11-27 13:22

    You can force the cell to commit the value as soon as you click the checkbox and then catch the CellValueChanged event. The CurrentCellDirtyStateChanged fires as soon as you click the checkbox.

    The following code works for me:

    private void grid_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            SendKeys.Send("{tab}");
        }
    

    You can then insert your code in the CellValueChanged event.

提交回复
热议问题