Link to home
Start Free TrialLog in
Avatar of dotnet0824
dotnet0824

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of gemailj
gemailj
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gyanendra Singh
Remove this line
dim dssubset = new dsSubset(); //Subset Dataset

and add this one

dim dssubset = DsSTUDENTS.Clone()
Avatar of dotnet0824
dotnet0824

ASKER

I tried  CLONE. it  still says it cant bind to the new display Member
use this

Dataset  dssubset = DsSTUDENTS.Clone();

Yes bond. I used that then copied all rows which r active to the dsSubSet and tried to bind
i tried this it works (Any idea whats wrong Bond with that)

DataView dvActive = DsSTUDENTS.Tables[0].DefaultView;
dvActive.RowFilter = "Active=1";
 
 
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMember = "Name";
this.combobox.ValueMember = "Student_ID";
Hi,
How did i get the row Values In the selectedchangeEvent of combo after I bind it to the dataView

DataView dvActive = DsSTUDENTS.Tables[0].DefaultView;
dvActive.RowFilter = "Active=1";
 this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMember = "Name";
this.combobox.ValueMember = "Student_ID";