[英]How to get listBox selected item as KeyValuePair<string, string> in C#?
ListBox
object is binded with BindingList<KeyValuePair<string, string>>
ListBox
对象与BindingList<KeyValuePair<string, string>>
绑定BindingList<KeyValuePair<string, string>>
On SelectionChanged event I need to get selected item as KeyValuePair<string, string>
在SelectionChanged事件中,我需要将所选项目作为
KeyValuePair<string, string>
Following code gives error because KeyValuePair can't be used as reference type. 以下代码给出错误,因为KeyValuePair不能用作引用类型。
KeyValuePair<string, string> selectedProperty = listProperties.SelectedItem as KeyValuePair<string, string>;
What is good work-around for this? 什么是好的解决方法?
尝试使用直接铸造的,而不是as
:
var selectedProperty = (KeyValuePair<string, string>)listProperties.SelectedItem;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.