D
DS
How do I go about binding a "struct" datatype to a comboBox? When I bind it
by means of the DataSource, it doesn't give any error, but the comboBox just
gets populated with "WindowsApplication2.Form1+Unit". Uncommenting the
DisplayMember line has no effect. Uncommenting the ValueMember results in a
crash: "Could not bind to the new display member\nParameter name:
newDisplaymember". How can I get this to work? Thanks in advance.
Here is the code:
private void button3_Click(object sender, System.EventArgs e)
{
Unit[] unit = new Unit[3];
unit[0].id = 0;
unit[0].text = "honda";
unit[1].id = 1;
unit[1].text = "gm";
unit[2].id = 2;
unit[2].text = "toyota";
MessageBox.Show(unit[0].text); // correctly shows honda
comboBox1.DataSource = unit;
//comboBox1.ValueMember = "id";
//comboBox1.DisplayMember = "text";
}
private struct Unit
{
public string text;
public int id;
}
by means of the DataSource, it doesn't give any error, but the comboBox just
gets populated with "WindowsApplication2.Form1+Unit". Uncommenting the
DisplayMember line has no effect. Uncommenting the ValueMember results in a
crash: "Could not bind to the new display member\nParameter name:
newDisplaymember". How can I get this to work? Thanks in advance.
Here is the code:
private void button3_Click(object sender, System.EventArgs e)
{
Unit[] unit = new Unit[3];
unit[0].id = 0;
unit[0].text = "honda";
unit[1].id = 1;
unit[1].text = "gm";
unit[2].id = 2;
unit[2].text = "toyota";
MessageBox.Show(unit[0].text); // correctly shows honda
comboBox1.DataSource = unit;
//comboBox1.ValueMember = "id";
//comboBox1.DisplayMember = "text";
}
private struct Unit
{
public string text;
public int id;
}