You must create your own class type and override the ToString() method to return the text you want.
(您必须创建自己的类类型并覆盖ToString()方法以返回所需的文本。)
Here is a simple example of a class you can use: (以下是您可以使用的类的简单示例:)
public class ComboboxItem
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
The following is a simple example of its usage:
(以下是其用法的简单示例:)
private void Test()
{
ComboboxItem item = new ComboboxItem();
item.Text = "Item text1";
item.Value = 12;
comboBox1.Items.Add(item);
comboBox1.SelectedIndex = 0;
MessageBox.Show((comboBox1.SelectedItem as ComboboxItem).Value.ToString());
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…