【发布时间】:2011-12-02 14:02:00
【问题描述】:
我有一个像这样填充的组合框:
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;
}
}
我有一个值,例如“Value1”。如何将组合框的 selectedItem 设置为对象 {Label 1, Value1}?
我试过了:
this.reqTypeInput.SelectedIndex = this.reqTypeInput.Items.IndexOf("Value1");
【问题讨论】: