定义一个类,有两个属性
public class ValueObject{
private string _name;
private string _value;
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Value
{
get { return _value; }
set { _value = value; }
}
}
然后,用一个
ArrayList list = new ArrayList();
for(int i=0; i<3; i++)
{
ValueObject vo = new ValueObject();
vo.Name = "a";
vo.Value = "1";
list.add(vo);
}
ComboBox cbb = new ComboBox();
cbb.DataSource = list;
cbb.DisplayMember = "Name";
cbb.ValueMember = "Value";
这样就OK了,取值只要cbb.SelectedValue就取到了。
转自http://hi.baidu.com/nirvanan/blog/item/c45ab7b628ebecfd30add149.html