WinForms CheckedListBox control Select ALL Implementation
Recently I am working on windows based application after a long back in which I am using ChekedListBox control where I need to list all the subdistricts information based on the selected district in other dropdownList Control.
In this way, I want to have a Select ALL item as the first checkbox in the CheckedListBox. When I click on ‘ALL’ remaining all checkbox should be checked and vise versa.
Following is code snippet to implement this functionality in SelectedIndexChanged event occurs
bool isSelectAll = false; if (chkSubDistrict.CheckedItems.Contains("All")) { isSelectAll = true; } else { isSelectAll = false; } for (int i = 0; i < chkSubDistrict.Items.Count; i++) { if (chkSubDistrict.Items[i].ToString() != "All") chkSubDistrict.SetItemChecked(i, isSelectAll); }
Here the above code is self-explanatory. Just a small snippet hope it makes you some help.