如何代码增加combox的项。实际值和显示值
哪位大神给个例子
值是动态变化的
------解决方案--------------------public class ListItem
{
public string Name{get;set;}
public object Value{get;set;}
public ListItem(string name, object value)
{
Name=name;
Value=value;
}
public override string ToString()
{
return Name;
}
}
comboBox1.Items.Add(new ListItem("内容1",1));
comboBox1.Items.Add(new ListItem("内容2",2));
...
------解决方案--------------------comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "id";
comboBox1.Items.Add(new { id = 1, name = "a" });
comboBox1.Items.Add(new { id = 2, name = "b" });