我有简单的comboBox:
cb_listaUczniow.ValueMember = "Key";
cb_listaUczniow.DisplayMember = "Value";
我有这个Form的构造函数(classID还不重要):
MyForm(int classID, string selectedName)
{
cb_listaUczniow.ValueMember = "Key";
cb_listaUczniow.DisplayMember = "Value";
comboBox.DataSource = new BindingSource(makeList(classID), null);
}
makeList返回字典
以及如何在comboBox项目中选择名称为selectedName的“Value”(displayMember)?
例如(伪代码):
MyForm(3, "Gall Anonim") -> comboBox.Item.Selected = comboBox.Item.where("Value" == "Gall Anonim");
我如何设定?
答案 0 :(得分:1)
如果我理解正确,您只需将ComboBox
的{{1}}属性设置为相应的值:
SelectedValue
这将使“Gall Anonim”成为comboBox.SelectedValue = 3;
的所选项目。