Question : combobox Winform cannot bind to valuemember

Hi I have a Dataset of studentData

I make a subset of Active Students into a different Dataset... Original dataset bound , I have no problems

I try binding this Dataset to the combo. It fails to bind.  

If I bind the Original Dataset(dsStudents)  to the combo its fine. It only fails if i bind it to subset At valueMember property

  dim dssubset = new dsSubset(); //Subset Dataset

  DataRow[] rows = DsSTUDENTS.Tables[0].Select("Active=1");  //Original Dataset

   dssubset = MakeDataSet(rows); //to make subset of original dataset
 


 public DataSet MakeDataSet(DataRow[] drRows)
        {
            DataTable dt = new DataTable();
            foreach (DataRow dr in drRows)
            {
                dt.ImportRow(dr);
            }
            DataSet dsNew = new DataSet();
            dsNew.Tables.Add(dt);
            return dsNew;

        }


                  ////// THIS WORKS FINE ////////////////////
                    this.COMBOBOX.DataSource = dsStudents.Tables[0];
                    this.ComboBox.DisplayMember = "Name";
                    this.combobox.ValueMember = "Student_ID";  


//////////////////////////FAILS HERE SUBSET OF ORIGINAL DATASET
                 
                    this.COMBOBOX.DataSource = dssubset.Tables[0];
                    this.ComboBox.DisplayMember = "Name";
                    this.combobox.ValueMember = "Student_ID"; //FAILS HERE SAYING CANNOT BIND TO DATAMEMBER

Answer : combobox Winform cannot bind to valuemember

instead of using .Select()
try use DsSTUDENTS.Tables[0].DefaultView.RowFilter  Property


try this code
1:
2:
3:
4:
5:
6:
7:
DataView dvActive = DsSTUDENTS.Tables[0].DefaultView;
dvActive.RowFilter = "Active=1";
 
 
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMember = "Name";
this.combobox.ValueMember = "Student_ID";
Random Solutions  
 
programming4us programming4us