Reputation: 5884
I have a CheckedListBox
like this:
:'''''''''''''''/\
: [ ] item1 ||
: [x] item2 ||
: [ ] item3 ##
: [ ] item4 ||
: [x] item5 ||
L...............\/
Now I want to extract indexes of checked items:
int[] indexes = ExtractCheckedIndexes (myCheckedListBox);
Now indexes should have 2 elements = { 1, 4 }.
How to achieve this?
Upvotes: 6
Views: 18734
Reputation: 13844
int[] indexes = myCheckedListBox.CheckedIndices.Cast<int>().ToArray()
Upvotes: 14
Reputation: 2321
MSDN example:
http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.checkeditems.aspx
Upvotes: 2