I have a checkbox that when a checked checks all items in a CheckedListBox.
When the checkbox goes unchecked it should uncheck all items in the list.
Code:
if (checkBoxCheckAllPrivileges.Checked)
for (int i = 0; i < checkedListBoxUsersWhoSee.Items.Count; i++)
checkedListBoxUsersWhoSee.SetItemChecked(i, true);
else
for (int i = 0; i < listBoxUsers.Items.Count; i++)
checkedListBoxUsersWhoSee.SetItemChecked(i, false);
Is the problem in this code?
Does the .SetitemChecked work giving it the parameter as false?
Is there any other way to uncheck the items?
You have given wrong item in else part for loop,
if (checkBoxCheckAllPrivileges.Checked)
for (int i = 0; i < checkedListBoxUsersWhoSee.Items.Count; i++)
checkedListBoxUsersWhoSee.SetItemChecked(i, true);
else
for (int i = 0; i < checkedListBoxUsersWhoSee.Items.Count; i++)
checkedListBoxUsersWhoSee.SetItemChecked(i, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With