简体   繁体   English

如何获得所选物品的价值

[英]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#. 我正在使用wpf和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: 但是,对于ComboBox中的每个项目,请关联一个值,例如:

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. 现在,我想获得此标签。例如,当选择了相关的项目时,用户选择Item1,并且在变量中将标签的价位定为Home ...但是不起作用。 So what is the way to get it? 那么如何获得它呢?

你可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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