Setting the selected value of a ListBoxView as a string (C#)
When a value is selected in a ListBoxView, How could the selection be stored as a string / variable, so I can then call a开发者_如何学Cnother method that will use this string to perform an action?
If the Items in your listbox are all strings, you could use
System.Windows.Forms.ListBox lb= new ListBox();
            lb.SelectedItem.ToString();
Otherwise, we will need to know the types of items you have added to the listbox.
If you using ListBox get selected item like this:
string item = listBox1.SelectedItem.ToString();
If you using ListView get selected item(s) depending on MultiSelect property:
- Use this code if MultiSelect property = false - string itemName = listView.SelectedItems[0].Name;
- Use this code if MultiSelect property = true - foreach (ListViewItem item in ltvMainMenu.SelectedItems) { string itemName = item.Name; }
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论