//编辑的同时提交当前编辑状态 private void dataGridViewTaskInfo_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dataGridViewTaskInfo.IsCurrentCellDirty) { dataGridViewTaskInfo.CommitEdit(DataGridViewDataErrorContexts.Commit);//CommitEdit :将当前单元格中的更改提交到数据缓存,但不结束编辑模式 } }
//设置其他行的Check为false
private void dataGridViewTaskInfo_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//第一时间获取CheckBox的选中状态
string _selectValue = dataGridViewTaskInfo.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();//FormattedValue是操作提交后的结果,而EditedFormattedValue是当前的结果,不管结果是否已经提交。
if (_selectValue == "True")
{
for (int i = 0; i < dataGridViewTaskInfo.Rows.Count; i++)
{
if (i != e.RowIndex)
{
dataGridViewTaskInfo.Rows[i].Cells[0].Value = false;
}
}
}
}