public class yourItem
{
    public int id;
    public string name;
    public yourItem(int id,string name)
    {
         this.id  = id;
         this.name = name;
    }
    public override ToString()
    {
          return this.name;
    }
}yourItem item = new yourItem(1,"11");
combobox.items.add(item);((item)combobox.selectitem).id 就是你要的

解决方案 »

  1.   

    ListItem item;
    item = new ListItem("姓名","编号");
    ComboBox.Items.Add(item);
      

  2.   

    yufan565(雨凡) 
    我是winform程序,好象没有ListItem类
      

  3.   

    brightheroes(闭关):
    以前,我做的也是这样的
    但是,下拉时怎么显示为“编号” + “姓名”
    而不是显示为“命名空间” + “类名”;
    当然,combobox.items.add(obj);obj必须为object型的
      

  4.   

    //如果时操作表的话,可以用绑定,AddNew();
    //先事例化yourtable,yourdataSet。
    combobox.DataSource = "yourtable";
    combobox.DisplayMember = "yourtable.编号";
    combobox.ValueMember = "yourtable.姓名";
    combobox.DataBindings.Add("SelectedValue", yourdataSet,"yourtable.编号");(CurrencyManager) BindingContext["yourdataSet", "yourtable"].AddNew();;
      

  5.   

    public class ComboItem
    {
    private string id = "";
    private string name = "";
    public ComboItem(string sid,string sname)
    {
    id = sid;
    name = sname;
    }
    public string ID
    {
    get{return this.id;}
    set{this.id = value;}
    }
    public string Name
    {
    get{ return this.name;}
    set{this.name = value;}
    }
    }foreach(DataRow row in ds.Tables["WFBillState"].Rows)
    {
    ComboItem item=new ComboItem(row["WFStateID"].ToString(),row["WFStateName"].ToString());
    this.tbx_BillState.Items.Add(item);
    this.tbx_BillState.DisplayMember = "Name";
    this.tbx_BillState.ValueMember = "ID";
    }
      

  6.   

    foreach(DataRow row in ds.Tables["WFBillState"].Rows)
    是将数据加入
      

  7.   

    如果用用绑定的话,她会自动将所有数据取到combobox中,楼上是用foreach循环赋值到combobox
      

  8.   

    哈哈
    解决了
    自己写了个SearchComboBox控件
      

  9.   

    如果楼主是按照我说的那个方法作的
    那么:把选中的项转化为我们定义的类item((item)combobox.selectitem).id 就是你要的
      

  10.   

    to
    Hexudong1979(何须懂何必懂)因为combobox的Item.ADD(一个任意类型的变量)
    而显示的时候调用的是这个变量的ToString()方法
    如果这个类没有重载ToString()
    那么显示的结果就是命名空间 + 类名
    我在一楼的回答
    重写了ToString();
    public override ToString()
        {
              return this.name;
        }
    所以这样显示的就是name这个字段了
      

  11.   

    foreach(ComboItem item in tbx_BillState.Items)
    {
    if(item.ID==dg[dg.CurrentRowIndex,5].ToString())
    {
    int num=this.tbx_BillState.FindStringExact(item.Name,0);
    this.tbx_BillState.SelectedIndex=num;
    break;
    }
    }
      

  12.   

    http://www.yesky.com/20020226/218658_4.shtml