【发布时间】:2016-12-13 12:44:32
【问题描述】:
据我所知,Windows 窗体中的组合框只能保存一个值。我需要一个文本和一个索引,所以我创建了这个小类:
public class ComboboxItem {
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
我将一个项目添加到组合框中,如下所示:
ComboboxItem item = new ComboboxItem()
{
Text = select.Item1,
Value = select.Item2
};
this.comboBoxSelektion.Items.Add(item);
现在我的问题是:如何将组合框设置为特定项目? 我试过了,但是没有用:
this.comboBoxSelektion.SelectedItem = new ComboboxItem() { Text = "Text", Value = 1};
【问题讨论】: