如何在WinForms中按值选择组合框?我将组合框设置为以下内容:
ComboboxItem item = new ComboboxItem();
item.Text = "Test";
item.Value = 1;
cmbComboBox.Items.Add(item);
internal class ComboboxItem
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
我需要选择 Value = 1 的地方。
i.Value
强制转换为(int)
,然后在查询上调用FirstOrDefault()
,它将返回一个 ComboboxItem(或 null)。一旦你得到了它,就可以确定它在 Items 集合中的索引,以便设置 SelectedIndex()。 - Idle_Mind