C#的combobox能否实现存储键值对 比如说吧,我从数据表中取得数据,一项是名称,用于显示,另一项是编号,用于选中后插入数据库,这样就不用在插入的时候再去查一次数据库了,有实现方法吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以啊。DisplayMember显示名称,ValueMember是编号,就可以了。 this.comboBox1.DataSource=ds; this.comboBox1.DisplayMember ="Name"; this.comboBox1.ValueMember="ID"; DisplayMember显示名称,ValueMember编号,查查2属性的说明,就可以搞定了 combobox本来就是键值对存储的 this.comboBox1.DataSource=ds;this.comboBox1.DisplayMember ="Name";//comboBox要显示的数据的字段名称this.comboBox1.ValueMember="ID";//对应的编号的字段名称 this.comboBox1.DataSource=ds;this.comboBox1.DisplayMember ="Name";this.comboBox1.ValueMember="ID"; public class ItemVO : System.Object { public string id; public string desc; public ItemVO(string Id, string Desc) { this.id = Id; this.desc = Desc; } public override string ToString() { return this.desc; } public override bool Equals(System.Object obj) { if (this.GetType().Equals(obj.GetType())) { ItemVO that=(ItemVO) obj; return (this.id.Equals(that.id)); } return false; } public override int GetHashCode() { return this.id.GetHashCode();; } }================comboBox1.Items.Add(new ItemVO(id,name)); ((ItemVO)comboBox1.SelectedItem).id ((ItemVO)comboBox1.SelectedItem).desc 各位前辈,帮帮忙,谢谢各位! C++中的CStatic类型的窗体,在C#中用什么控件代替? 怎么让dataGridView增加一列用来显示行数 急,希望能指导一下 我现在有点放弃c#了,请问高手2! 怎样在C#中产生业务的流水号 求解webservice.htc的调用问题!!! 控件事件继承怎么写啊? 在WinForm里如何让DataGrid里一个单元格为不可修改?? 想请问一个基于WEB下的附件上传问题! 在自定义的DataGrid中,已添加列的使用 呵呵,今天又来了一个问题,不知道如何解决更好!
this.comboBox1.DisplayMember ="Name";
this.comboBox1.ValueMember="ID";
this.comboBox1.DisplayMember ="Name";//comboBox要显示的数据的字段名称
this.comboBox1.ValueMember="ID";//对应的编号的字段名称
this.comboBox1.DisplayMember ="Name";
this.comboBox1.ValueMember="ID";
{
public string id;
public string desc;
public ItemVO(string Id, string Desc)
{
this.id = Id;
this.desc = Desc;
} public override string ToString()
{
return this.desc;
} public override bool Equals(System.Object obj)
{
if (this.GetType().Equals(obj.GetType()))
{
ItemVO that=(ItemVO) obj;
return (this.id.Equals(that.id));
}
return false;
}
public override int GetHashCode()
{
return this.id.GetHashCode();;
}
}================
comboBox1.Items.Add(new ItemVO(id,name));
((ItemVO)comboBox1.SelectedItem).id
((ItemVO)comboBox1.SelectedItem).desc