WinForm中下拉框为ComboBox,没有绑定的概念,你可以自己定义一个类作为ComboBox的Item,
类中写两个属性,一为Text,一位Value,然后从写ToString()方法。即可存储Text和Value

解决方案 »

  1.   

    给你一段代码:
    先定义一个类:
       public class Titles
    {
    private string titleid,title;
    public Titles(string titleid,string title)
    {
    this.titleid=titleid;
    this.title=title;
    }
    public string TitleID
    {
    get{return titleid;}
    set{titleid=value;}
    }
    public string Title
    {
    get{return title;}
    set{title=value;}
    }
    }
    应用代码:
       string sConnString="Server=(local);DataBase=pubs;UID=sa;PWD=";
    SqlConnection cn=new SqlConnection(sConnString);
    cn.Open();
    string sSQL="SELECT * FROM Titles";
    SqlCommand cm=new SqlCommand(sSQL,cn);
            SqlDataReader dr=cm.ExecuteReader();
    Hashtable ht=new Hashtable();     Titles[] titleColl;

    while(dr.Read())
    {
    ht.Add(dr["title_id"].ToString(),dr["title"].ToString());

    }
     
        titleColl=new Titles[ht.Count];
    int i=0;
    IDictionaryEnumerator enumerator=ht.GetEnumerator();
    while(enumerator.MoveNext())
    {
    titleColl[i]=new Titles(enumerator.Key.ToString(),enumerator.Value.ToString());
    i++;
    }
                comboBox1.DataSource=titleColl;
    comboBox1.DisplayMember="Title";
    comboBox1.ValueMember="TitleID";