How to get listBox selected item as KeyValuePair<string, string> in C#?
ListBox object is binded with BindingList<KeyValuePair<string, string>>
On SelectionChanged event I need to get selected item as KeyValuePair<string, string>
Following code gives error because KeyValuePair can't be used as reference type.开发者_开发技巧
KeyValuePair<string, string> selectedProperty = listProperties.SelectedItem as KeyValuePair<string, string>;
What is good work-around for this?
Try using a direct cast instead of as:
var selectedProperty = (KeyValuePair<string, string>)listProperties.SelectedItem;
加载中,请稍侯......
精彩评论