[英]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.