2

ListBoxオブジェクトはとバインドされていますBindingList<KeyValuePair<string, string>>

SelectionChangedイベントで、選択したアイテムを次のように取得する必要がありますKeyValuePair<string, string>

KeyValuePairは参照型として使用できないため、次のコードはエラーになります。

KeyValuePair<string, string> selectedProperty = listProperties.SelectedItem as KeyValuePair<string, string>;

これに対する適切な回避策は何ですか?

4

1 に答える 1

9

の代わりに直接キャストを使用してみてくださいas:

var selectedProperty = (KeyValuePair<string, string>)listProperties.SelectedItem;
于 2011-06-19T19:10:05.213 に答える