比如说吧,我从数据表中取得数据,一项是名称,用于显示,另一项是编号,用于选中后插入数据库,这样就不用在插入的时候再去查一次数据库了,有实现方法吗?

解决方案 »

  1.   

    可以啊。DisplayMember显示名称,ValueMember是编号,就可以了。
      

  2.   

    this.comboBox1.DataSource=ds;
    this.comboBox1.DisplayMember ="Name";
    this.comboBox1.ValueMember="ID";
      

  3.   

    DisplayMember显示名称,ValueMember编号,查查2属性的说明,就可以搞定了
      

  4.   

    combobox本来就是键值对存储的
      

  5.   

    this.comboBox1.DataSource=ds;
    this.comboBox1.DisplayMember ="Name";//comboBox要显示的数据的字段名称
    this.comboBox1.ValueMember="ID";//对应的编号的字段名称
      

  6.   

    this.comboBox1.DataSource=ds;
    this.comboBox1.DisplayMember ="Name";
    this.comboBox1.ValueMember="ID";
      

  7.   

    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