【发布时间】:2018-08-15 12:38:12
【问题描述】:
我正在尝试获取ComboBox 的SelectedItem 的密钥,但不知道如何获取我所做的代码,
void CboBoxSortingDatagridview(ComboBox sender)
{
foreach (var v in DictionaryCellValueNeeded)
{
if (!DictionaryGeneralUsers.ContainsKey(v.Key) && v.Value.RoleId == Convert.ToInt32(((ComboBox)sender).SelectedItem)) // here getting value {1,Admin} i want key value which is 1 but how?
{
DictionaryGeneralUsers.Add(v.Key, (GeneralUser)v.Value);
}
}
dataGridViewMain.DataSource = DictionaryGeneralUsers.Values;
}
我是这样绑定组合框的,
cboRolesList.DataSource = new BindingSource(dictionaryRole, null);
cboRolesList.DisplayMember = "Value";
cboRolesList.ValueMember = "Key";
【问题讨论】:
标签: c# combobox keyvaluepair