combobox如何和Web一样

来源:百度知道 编辑:UC知道 时间:2024/06/27 12:18:29
我现在做一个项目,web的combobox可以让显示的数据和传递的数据分离,请问如何在windows程序中实现

写一个类,例如
public class Item
{
public string Text;
public string Value;
//我这里为简便用公有成员变量,你可以用属性
public Item(string text,string value)
{
this.Text = text;
this.Value = value;
}

public override string ToString()
{
return Text.ToString();
}
//每次给ComboBox添加Item的时候把这个Item对象添进去(ComboBox.Items.Add方法参数是Object型),
}

在取用的时候做一下类型的强转

((Item)combobox.Items[0]).Value就可以取到Value值