需要两个动作事件,不然,读取到的check状态总会慢一拍。
事件一:CurrentCellDirtyStateChanged事件代码
void PositionListDataView_CurrentCellDirtyStateChanged( object sender, EventArgs e)
{
DataGridView grid = sender as DataGridView;
if (grid != null )
{
grid.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
事件二:CellValueChanged事件
void PositionListDataView_CellValueChanged( object sender, DataGridViewCellEventArgs e)
{
DataGridView grid = sender as DataGridView;
if (grid != null && e.RowIndex >= 0 )
{
if (grid.Columns[e.ColumnIndex].Name == " Check " )
{
//业务代码
}
}
}