Get selectedvalues of multi-select list box

前端 未结 6 1148
[愿得一人]
[愿得一人] 2021-01-16 10:05

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

相关标签:
6条回答
  • 2021-01-16 10:35

    can be done this way.

    Int[] AllselectedIndex=ListBox1.GetSelectedIndices();
    
    0 讨论(0)
  • 2021-01-16 10:36

    You're looping the selected items already. Why not just call

    MessageBox.Show(list.ToString()); 
    
    0 讨论(0)
  • 2021-01-16 10:37

    You should be pulling the value from your list variable not from the list_box object.

    0 讨论(0)
  • 2021-01-16 10:39

    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!

    0 讨论(0)
  • 2021-01-16 10:47
    foreach (var list in list_box.SelectedItems)
    {             
        MessageBox.Show(list.ToString());
    }
    
    0 讨论(0)
  • 2021-01-16 10:49

    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());         
    } 
    
    0 讨论(0)
提交回复
热议问题