Hi
I have a checkedlistbox with some iteams and "All" item, like this:
O All
O Item1
O Item 2
O Item 3
O ...
Now, I want to do the follow actions:
1. check all iteams if item "All" is checked, and uncheack all iteams if item "All" is unchecked
2. if "All" is checked and the user uncheck ItemX "All" will be unchecked as well.
3. Check "All" if the user check all Items (and "All" was unchecked)
I write this code (for 1-2, #3 I haven't done yet):
private void clb_FilterComponet_ItemCheck(object sender, ItemCheckEventArgs e) { if (dontRunHandler) return; dontRunHandler = true; if (e.Index == 0) // check or uncheck "all" { bool toCheck = true; if (e.NewValue == CheckState.Unchecked) toCheck = false; for (int i = 1; i < clb_FilterComponet.Items.Count; i++) clb_FilterComponet.SetItemChecked(i, toCheck); } else if (e.NewValue == CheckState.Unchecked) // remove All v clb_FilterComponet.SetItemCheckState(0, CheckState.Unchecked); dontRunHandler = false; }
My question is, is there another way, more effective, to perfrom it ?
Thank you!