Spiga

关于Winform DataGridView的CellValueChanged事件不能立即处理的问题

2010-12-16 10:38 by Dev.Hong, 147 visits, 收藏, 编辑

DataGridView.CellValueChanged 事件在用户指定的值提交时发生,用户指定的值通常是在焦点离开单元格时提交。

但是,对于复选框单元格,您通常希望立即处理更改。要在单击单元格时提交更改,必须处理 DataGridView.CurrentCellDirtyStateChanged 事件。在处理程序中,如果当前单元格是复选框单元格,将调用 DataGridView.CommitEdit 方法并传入 Commit 值。

 

void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    
if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}