开发者

How to get listBox selected item as KeyValuePair<string, string> in C#?

开发者 https://www.devze.com 2023-03-14 04:22 出处:网络
ListBox object is binded with BindingList<KeyValuePair<string, string>> On SelectionChanged event I need to get selected item as KeyValuePair<string, string>

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

精彩评论

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