![](/img/trans.png)
[英]how to add the selected item from a listbox to list <string> in c#
[英]How to get listBox selected item as KeyValuePair<string, string> in C#?
ListBox
對象與BindingList<KeyValuePair<string, string>>
綁定BindingList<KeyValuePair<string, string>>
在SelectionChanged事件中,我需要將所選項目作為KeyValuePair<string, string>
以下代碼給出錯誤,因為KeyValuePair不能用作引用類型。
KeyValuePair<string, string> selectedProperty = listProperties.SelectedItem as KeyValuePair<string, string>;
什么是好的解決方法?
嘗試使用直接鑄造的,而不是as
:
var selectedProperty = (KeyValuePair<string, string>)listProperties.SelectedItem;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.