我有填充像这样的组合框:根据键值对设置组合框的selecteditem。
this.reqTypeInput.Items.Add(new RequestType("Label 1", "Value1"));
this.reqTypeInput.Items.Add(new RequestType("Label 2", "value2"));
this.reqTypeInput.Items.Add(new RequestType("Label 3", "value3"));
我的RequestType类是:
class RequestType
{
public string Text { get; set; }
public string Value { get; set; }
public RequestType(string text, string val)
{
Text = text;
Value = val;
}
public override string ToString()
{
return Text;
}
}
我的值。例如, “值1”。如何将组合框的selectedItem设置为对象{Label 1,Value1}?
我曾尝试:
this.reqTypeInput.SelectedIndex = this.reqTypeInput.Items.IndexOf("Value1");