我们有这样的字典:
var dictionary = new Dictionary<int, int> { { 0, 100 }, { 1, 202 }, { 2, 309 }, };
等等,有很多值。将字典绑定到comboBox上,如下所示:
comboBox1.ItemsSource = dictionary;
comboBox1.DisplayMemberPath = "Value";
我想知道如何获取该组合框的选定值,因为 comboBox.Text 只适用于手动输入的值,而这段代码:
string value = comboBox1.SelectedValue.ToString();
返回值类似于[1,202],而我需要清楚的int TValue“202”。我无法找到类似的问题,所以在这里提问,并希望答案对其他人有用。
Dictionary<int,int>
或Dictionary<string,int>
创建BindingSource
的替代方案:https://dev59.com/umw15IYBdhLWcg3wxuch - MethodMan