简体   繁体   中英

How to get value of the selected item

I want to get the value of the selected item of the combobox. I'm using wpf and c#.

I make something like that:

 String c = Combobox.SelectedItem.Tag

No, all the answers are wrong here, but perhaps it is also a bit 'my fault because I could not express myself well. However, for each item in the ComboBox associate a value, for example:

Item1 (Value) => Home (Tag)<br>
Item2 (Value) => Away (Tag)<br>
Item3 (Value) => Half (Tag)<br>


and this is September Tag like:

Now I want get this tag When the related item is selected, for example: user select Item1 and in the variable is valorize Home with tags ... But isn't working. So what is the way to get it?

你可以这样做:

string c = comboBox1.SelectedValue != null ? comboBox1.SelectedValue.ToString() : string.Empty;
String c=combobox.SelectedValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM