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].Selec t("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.DisplayMembe r = "Name";
this.combobox.ValueMember = "Student_ID";
////////////////////////// FAILS HERE SUBSET OF ORIGINAL DATASET
this.COMBOBOX.DataSource = dssubset.Tables[0];
this.ComboBox.DisplayMembe r = "Name";
this.combobox.ValueMember = "Student_ID"; //FAILS HERE SAYING CANNOT BIND TO DATAMEMBER
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].Selec
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.DisplayMembe
this.combobox.ValueMember = "Student_ID";
//////////////////////////
this.COMBOBOX.DataSource = dssubset.Tables[0];
this.ComboBox.DisplayMembe
this.combobox.ValueMember = "Student_ID"; //FAILS HERE SAYING CANNOT BIND TO DATAMEMBER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried CLONE. it still says it cant bind to the new display Member
use this
Dataset dssubset = DsSTUDENTS.Clone();
Dataset dssubset = DsSTUDENTS.Clone();
ASKER
Yes bond. I used that then copied all rows which r active to the dsSubSet and tried to bind
ASKER
i tried this it works (Any idea whats wrong Bond with that)
DataView dvActive = DsSTUDENTS.Tables[0].Defau ltView;
dvActive.RowFilter = "Active=1";
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMembe r = "Name";
this.combobox.ValueMember = "Student_ID";
DataView dvActive = DsSTUDENTS.Tables[0].Defau
dvActive.RowFilter = "Active=1";
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMembe
this.combobox.ValueMember = "Student_ID";
ASKER
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].Defau ltView;
dvActive.RowFilter = "Active=1";
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMembe r = "Name";
this.combobox.ValueMember = "Student_ID";
How did i get the row Values In the selectedchangeEvent of combo after I bind it to the dataView
DataView dvActive = DsSTUDENTS.Tables[0].Defau
dvActive.RowFilter = "Active=1";
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMembe
this.combobox.ValueMember = "Student_ID";
dim dssubset = new dsSubset(); //Subset Dataset
and add this one
dim dssubset = DsSTUDENTS.Clone()