Get the value of indeces in CheckedListBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear helpers,

how do I get the value indeces of items checked in CheckedListBox?
I have tried to do this but It doesn't seem work??

foreach(int index in caseIssuesCheckedListBox.CheckedIndices)
{
for (int i = 0; i < caseIssuesCheckedListBox.Items.Count; i++)
{
if(caseIssuesCheckedListBox.GetItemCheckState(index) == CheckState.Checked)
{

//Method goes here...
}
}
}

Thank you.
 
0582 said:
Dear helpers,

how do I get the value indeces of items checked in CheckedListBox?
I have tried to do this but It doesn't seem work??

foreach(int index in caseIssuesCheckedListBox.CheckedIndices)
{
for (int i = 0; i < caseIssuesCheckedListBox.Items.Count; i++)
{
if(caseIssuesCheckedListBox.GetItemCheckState(index) == CheckState.Checked)
{

//Method goes here...
}
}
}

Thank you.

You can access checked items directly by "CheckedListBox.CheckedItems".
Then you can easily iterate them and do // methods goes here...

Cheers

Marcin
 
Dear Marcin,

I tried that, It doesnt work as well, it even gives an error of:
An unhandled exception of type 'System.InvalidCastException' occurred in SF.exe
Additional information: Specified cast is not valid.

Any other idea??

Thx.
 
Back
Top