CheckedListBox and list of checked items with their indexes
Asked Answered
A

2

6

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?

Amphi answered 27/9, 2012 at 12:49 Comment(0)
D
2

MSDN example:

http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.checkeditems.aspx

Daryn answered 27/9, 2012 at 12:50 Comment(2)
Thanks, that ToString() trip me up.Amphi
The answer by Patrik Svensson should be the accepted answer. This link does not provide an answer...and it is just a link anyway.Kalgan
K
14
int[] indexes = myCheckedListBox.CheckedIndices.Cast<int>().ToArray()
Karakalpak answered 27/9, 2012 at 13:43 Comment(1)
Actually I access them like that: myCheckedListBox.CheckedIndices[0].Amphi
D
2

MSDN example:

http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.checkeditems.aspx

Daryn answered 27/9, 2012 at 12:50 Comment(2)
Thanks, that ToString() trip me up.Amphi
The answer by Patrik Svensson should be the accepted answer. This link does not provide an answer...and it is just a link anyway.Kalgan

© 2022 - 2024 — McMap. All rights reserved.