簡體   English   中英

如何將listBox選中的項目作為KeyValuePair <string, string> 在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM