[英]Checked list box Checked items Verification
我有一个Checkedlistbox,其中包含以下信息:
*************
*__All Cells*
*__Cell A *
*__Cell B *
*__Cell C *
*__Cell D *
*************
我想检查我想要的每个字段,但是如果我选中“所有单元格”复选框,所有字段都必须自动检查,我已经可以执行此操作。 需要帮助的部分,如果我想取消选中“所有单元格”复选框时,所有单元格都应取消选中。
这是我使用的代码。 请帮我解决一下这个。
private void Cells_CheckedListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (Cells_CheckedListBox.GetItemChecked(Cells_CheckedListBox.Items.IndexOf("All Cells")))
{
for (int i = 0; i < Cells_CheckedListBox.Items.Count; i++)
{
Cells_CheckedListBox.SetItemCheckState(i, CheckState.Checked);
}
}
}
您似乎完全是在错误的事件中执行此操作。 您应该处理ItemCheck
事件。
private void Cells_CheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
int allIndex = Cells_CheckedListBox.Items.IndexOf("All Cells");
if (e.Index == allIndex)
{
for (int i = 0; i < Cells_CheckedListBox.Items.Count; i++)
{
if (i != allIndex)
Cells_CheckedListBox.SetItemCheckState(i, e.NewValue);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.