How to detect DataGridView CheckBox event change?

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

    Removing the focus after the cell value changes allow the values to update in the DataGridView. Remove the focus by setting the CurrentCell to null.

    private void DataGridView1OnCellValueChanged(object sender, DataGridViewCellEventArgs dataGridViewCellEventArgs)
    {
        // Remove focus
        dataGridView1.CurrentCell = null;
        // Put in updates
        Update();
    }
    
    private void DataGridView1OnCurrentCellDirtyStateChanged(object sender, EventArgs eventArgs)
    {
        if (dataGridView1.IsCurrentCellDirty)
        {
            dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
        }
    
    }
    

提交回复
热议问题