How to detect DataGridView CheckBox event change?

后端 未结 16 2385
离开以前
离开以前 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:21

    jsturtevants's solution worked great. However, I opted to do the processing in the EndEdit event. I prefer this approach (in my application) because, unlike the CellValueChanged event, the EndEdit event does not fire while you are populating the grid.

    Here is my code (part of which is stolen from jsturtevant:

    private void gridCategories_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == gridCategories.Columns["AddCategory"].Index)
        {
            //do some stuff
        }
    }
    
    
    
    private void gridCategories_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
    {
        if (e.ColumnIndex == gridCategories.Columns["AddCategory"].Index)
        {
            gridCategories.EndEdit();
        }
    }
    

提交回复
热议问题