If you have a large list of items, this approach may be a little more effective for unchecking. This requires that you only follow the items that are actually checked:
private void UncheckAllItems() { while (chklistbox.CheckedIndices.Count > 0) chklistbox.SetItemChecked(chklistbox.CheckedIndices[0], false); }
And if you use several CheckedListBox controls throughout your project and want to take another step, you can add it as an extension method:
public static class AppExtensions { public static void UncheckAllItems(this System.Windows.Forms.CheckedListBox clb) { while (clb.CheckedIndices.Count > 0) clb.SetItemChecked(clb.CheckedIndices[0], false); } }
Call extension method:
chklistbox.UncheckAllItems();
brsfan
source share