nch*_*che 0 c# combobox winforms
我有一个组合框,我这样填充:
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"));
Run Code Online (Sandbox Code Playgroud)
我的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;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个值,例如"Value1".如何将组合框的selectedItem设置为对象{Label 1,Value1}?
我试过了:
this.reqTypeInput.SelectedIndex = this.reqTypeInput.Items.IndexOf("Value1");
Run Code Online (Sandbox Code Playgroud)