就是想把comboBox1控件显示一个表的一个字段列!

解决方案 »

  1.   


     //定义DataTable表
     public DataTable DTTableName = new DataTable ("表名");
     //获取表记录
     private void GetList()
     {
       this.DTTableName = .....;//获取方法不写了,应该会吧。
     }
      
     //绑定列表
     private void BindItemDeail()
     {
        comboBox1.DisplayMember = "显示的字段名";//(比方说这个是名称)
        comboBox1.Validating = "实际值";         //(比方说这个是ID或编号)
        comboBox1.DataSource =this.DTTableName.DefaultView;
     }
      

  2.   

    comboBox1.Validating = "实际值";  
    改成comboBox1.ValueMember = "实际值";  
      

  3.   

    2楼高手,我这样写,还是不行,我把代码COPY过来,你看看
    string connString = "Data Source=LEAHANDE;Initial Catalog=colin;User ID=mis ;Password=mis";
            string sql = "select custcode,custname from S_customer";
            DataSet ds = new DataSet();
              SqlConnection conn = new SqlConnection(connString);
                SqlDataAdapter ada = new SqlDataAdapter(sql, conn);
                ada.Fill(ds);
                this.comboBox1.DataSource = ds;
                this.comboBox1.DisplayMember = "custcode";
                this.comboBox1.ValueMember = "部门编码";
               
     总是提示,无法显示绑定新的成员。看看还有哪些不对呀,
      

  4.   

    不要用DataSet 用DataTable string connString = "Data Source=LEAHANDE;Initial Catalog=colin;User ID=mis ;Password=mis"; 
            string sql = "select custcode,custname from S_customer"; 
            DataTable dt = new DataTable (); 
            SqlConnection conn = new SqlConnection(connString); 
            conn.open(); 
            SqlDataAdapter ada = new SqlDataAdapter(sql, conn); 
            ada.Fill(dt); 
            this.comboBox1.DisplayMember = "custcode"; 
            this.comboBox1.ValueMember = "部门编码"; //这个显示的也是用数据库的字段,就是你没个编号都用对应名称的字段吧。
            this.comboBox1.DataSource =dt.DefaultView;        
      

  5.   

    this.comboBox1.ValueMember = "custcode"; 
    也还是相同错误提示
      

  6.   


    string connString = "Data Source=LEAHANDE;Initial Catalog=colin;User ID=mis ;Password=mis"; 
                string sql = "select custcode,custname from S_customer"; 
                DataTable dt = new DataTable();
                SqlConnection conn = new SqlConnection(connString);
                conn.Open();
                SqlDataAdapter ada = new SqlDataAdapter(sql, conn);
                ada.Fill(dt);
                this.comboBox1.DisplayMember = "custname";
                this.comboBox1.ValueMember = "custcode"; //这个显示的也是用数据库的字段,就是你没个编号都用对应名称的字段吧。
                this.comboBox1.DataSource = dt.DefaultView;   
      

  7.   

    //打错,反了
    this.comboBox1.DisplayMember = "custname";//这个显示的也是用数据库的字段,就是你没个编号都用对应名称的字段吧。
    this.comboBox1.ValueMember = "custcode"; //这个是存在里面的值
      

  8.   

    楼主,你不能把ds直接绑定到下拉框啊,
    this.comboBox1.DataSource = ds; 
    这一句应该改成:
    this.comboBox1.DataSource = ds.table[0];
    这样就可以了