我有一个复选框[All
]和如下一个DataGridView:如何处理datagridview中的组合框事件?
我想:
- 内部datagridview的,如果所有的复选框被选中,复选框[
All
]是检查,否则如果所有复选框未选中,复选框[All
]未选中 - 内部datagridview,有一个未选中复选框,复选框[
All
]没有被选中
我尝试过,但我没有能够做到这一点:
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
bool isAllCheck = false;
if (e.ColumnIndex == 0)
{
foreach (DataGridViewRow row in dataGridView.Rows)
{
DataGridViewCheckBoxCell chk = row.Cells[0] as DataGridViewCheckBoxCell;
isAllCheck = Convert.ToBoolean(chk.Value);
if (!isAllCheck)
{
break;
}
}
if (chkAllItem.Checked && !isAllCheck)
{
chkAllItem.Checked = false;
}
if (!chkAllItem.Checked && isAllCheck)
{
chkAllItem.Checked = true;
}
}
}
private void dataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (this.dataGridView.IsCurrentCellDirty)
{
this.dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
这些任何提示将是很大的帮助。提前致谢。
_ “不能够做到这一点” _ ....什么没有奏效? –
我很抱歉没有清楚解释。 “不能这样做”....意思是:在datagridview里面,如果我取消选择一个复选框,所有的复选框都没有选中。不过,得益于TaW先生的指导,我做得很好。 – MinhKiyo