sarahjackel
asked on
Display and Value member binding to a ComboBox
Hello,
I am trying to bind the display and value members to a combobox from an arrayList that contains a custon Object.
I made the object "ComboItem" that holds a name and a value. Each of these are added to the Arraylist. The datasource line works, but it won't accept the names of the DisplayMember or the ValueMember.
What am I doing wrong? I've already tried changing the value variable in ComboItem as an int; and changing the case of the names.
thanks,
Sarah
private void MainForm_Load(object sender, EventArgs e) {
IList aList = new ArrayList();
ComboItem cItemNone = new ComboItem("None", "-1");
aList.Add(cItemNone);
foreach (DataRow dr in dataSet.Tables["Students"] .Rows) {
ComboItem cItem = new ComboItem(dr[1].ToString() ,dr[0].ToS tring());
aList.Add(cItem);
}
StudentComboBox.DataSource = aList;
StudentComboBox.DisplayMem ber = "name";
StudentComboBox.ValueMembe r = "value";
}
private class ComboItem {
public string Name;
public string Value;
public ComboItem(string name, string value) {
Name = name;
Value = value;
}
}
I am trying to bind the display and value members to a combobox from an arrayList that contains a custon Object.
I made the object "ComboItem" that holds a name and a value. Each of these are added to the Arraylist. The datasource line works, but it won't accept the names of the DisplayMember or the ValueMember.
What am I doing wrong? I've already tried changing the value variable in ComboItem as an int; and changing the case of the names.
thanks,
Sarah
private void MainForm_Load(object sender, EventArgs e) {
IList aList = new ArrayList();
ComboItem cItemNone = new ComboItem("None", "-1");
aList.Add(cItemNone);
foreach (DataRow dr in dataSet.Tables["Students"]
ComboItem cItem = new ComboItem(dr[1].ToString()
aList.Add(cItem);
}
StudentComboBox.DataSource
StudentComboBox.DisplayMem
StudentComboBox.ValueMembe
}
private class ComboItem {
public string Name;
public string Value;
public ComboItem(string name, string value) {
Name = name;
Value = value;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.