我有一堂类似于:
class ComboboxValue
{
public int Id { get; private set; }
public string Name { get; private set; }
public ComboboxValue(int id, string name)
{
Id = id;
Name = name;
}
public override string ToString()
{
return Name;
}
}
要从组合框中获取选定的值,我使用:
Combobox cb = new Combobox();
cb.Items.Add(new ComboboxValue(10, "Example value"));
ComboboxValue tmpComboboxValue = (ComboboxValue)cb.SelectedItem;
但是当我知道以前存储的 ID 时,如何设置 ComboBox 的索引?...对于此示例,ID:10(来自 sql 查询)