I have a Checkedlistbox that have the following information:
*************
*__All Cells*
*__Cell A *
*__Cell B *
*__Cell C *
*__Cell D *
*************
I want to check every field that i want, however i want to if I check the "All Cells" Checkbox, all the fields have to checked automatically, I already can do this. The part that need help if that I want that when i uncheck the "All Cells" checkbox all the cells are supposed to unchecked.
Here is the code that i use. Please help me with this.
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);
}
}
}
You seem to be doing this in the wrong event altogether. You should handle the ItemCheck
event.
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);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.