So, i have a checklistbox that contains string values like:
- asdf-432-qwer-vcxz
- rewq-123-qwer-vcxz
- rety-323-qw65-vcyt
- kjhf-232-ouyy-bjkl
- ...
And i have an array(onlineVaults) that contains some of the same values that in checklistbox like:
- rety-323-qw65-vcyt
- asdf-432-qwer-vcxz
Now i want to check only those values in checklistbox that are in the array. Others should be unchecked.
for (int i = 0; i < checklistbox.Items.Count; i++)
{
if (onlineVaults.Contains(checklistbox.Items[i]))
{
checklistbox.SetItemChecked(i, true);
}
}
I have tried it to figure out like this, but it doesn't work. It only checks one value and nothing else. What i should do?
elseblock to your if statement that sets the boxes to unchecked?onlineVaultscame from? Are you absolutely sure that there are values and not nulls there ? Are there multi-threading involved ?SelectionModeproperty merely controls how many items can be highlighted. At any time, an unlimited number of items can still be checked. Note that the docs even say: "For CheckedListBox objects, multiple selection is not supported. You can set the mode to one item or no items."