I have got a list box in multi select mode which is data bound with 15 values from a database. I have this code to display the selected values of each item selected in the l
can be done this way.
Int[] AllselectedIndex=ListBox1.GetSelectedIndices();
You're looping the selected items already. Why not just call
MessageBox.Show(list.ToString());
You should be pulling the value from your list variable not from the list_box object.
I came back to this issue and solved it by doing this:
foreach(int blah in multilistbox.SelectedIndices){
MessageBox.Show(blah.ToString());
}
Thanks for your help!
foreach (var list in list_box.SelectedItems)
{
MessageBox.Show(list.ToString());
}
I think you may have a logic error in your code. You are looping through the SelectedItems
, but your MessageBox
is still using the list_box
to display a value. How about this?
foreach (var list in list_box.SelectedItems)
{
MessageBox.Show(list.ToString());
}