如何实现在COMBOBOX控件中点击下拉箭头,在下拉列表里显示数据表TABLE1中一个字段 ZD的所有值。

解决方案 »

  1.   

    你可以把数据自己写到items中,也可以用动态绑定来做。
      

  2.   

    数据绑定啊..for example:combobox绑定student数据库studentDetails表的sname字段..SqlConnection con=new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
    SqlDataAdapter sda=new SqlDataAdapter("select * from studentDetails",con);
    DataSet ds=new DataSet();
    sda.Fill(ds,"student");
    this.ComboBox1.DataSource=ds.Tables["student"];
    this.ComboBox1.DisplayMember="sname";
      

  3.   

    第一种方法,用绑定的方法:
    comboBox1.DataSource = 你的dataTable;
    comboBox1.DisplayMember = "LongName";
    comboBox1.ValueMember = "ShortName" ;第二种方法,用添加元素的方法:
    DataTable dt = new DataTable();
    //dt = getData();
    ComboBox cb = new ComboBox();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
    cb.Items.Add(dt.Rows[i]["指定列"]);
    }