开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜