Home > DeveloperSection > Forums > Checkbox Selected Index is selected
john rob

Total Post:108

Points:756
Posted on    January-29-2014 11:30 PM

 C# C# 
Ratings:


 1 Reply(s)
 662  View(s)
Rate this:

I have a simple IF statement in my code that i want to prompt the user if the item in index 2 of my checkedlistbox1 is selected.

It works when index 2 by itself is selected BUT does not work when other items including index 2 are checked in my checklist box. Below is what i have that works, now i just need it to work when 2 and others are selected.

if (checkedListBox1.SelectedIndex == 2)

{

   MessageBox.Show("Note to send email", "Note", MessageBoxButtons.OK);

}



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-29-2014 11:50 PM

Hi John,

Replace that code with

if (checkedListBox1.SelectedIndices.Contains(2))

{

   MessageBox.Show("Note to send email", "Note", MessageBoxButtons.OK);

}

That will check if 2 is among all selected items.


Don't want to miss updates? Please click the below button!

Follow MindStick