我們的字典是這樣的:如何獲得的SelectedValue的價值組合框充滿字典
var dictionary = new Dictionary<int, int> { { 0, 100 }, { 1, 202 }, { 2, 309 }, };
等很多價值觀。字典綁定到組合框是這樣的:
comboBox1.ItemsSource = dictionary;
comboBox1.DisplayMemberPath = "Value";
我不知道如何可以得到這個組合框的SelectedValue,如果comboBox.Text僅適用於手動輸入值,並驗證碼:
string value = comboBox1.SelectedValue.ToString();
返回值像[1,202],而我需要明確的int TValue「202」。我無法找到類似的問題,所以我在那裏問它,並希望答案可能對其他人有用。
使用此替代方法學習如何使用「字典或字典」創建'BindingSource'' http://stackoverflow.com/questions/6412739/binding-combobox-using-dictionary-as-the- datasource –
MethodMan
2013-03-22 21:16:23