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 "WindowsApplica tion2.Form1+Uni t". Uncommenting the
DisplayMember line has no effect. Uncommenting the ValueMember results in a
crash: "Could not bind to the new display member\nParamet er name:
newDisplaymembe r". How can I get this to work? Thanks in advance.
Here is the code:
private void button3_Click(o bject sender, System.EventArg s 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.DataS ource = unit;
//comboBox1.Value Member = "id";
//comboBox1.Displ ayMember = "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 "WindowsApplica tion2.Form1+Uni t". Uncommenting the
DisplayMember line has no effect. Uncommenting the ValueMember results in a
crash: "Could not bind to the new display member\nParamet er name:
newDisplaymembe r". How can I get this to work? Thanks in advance.
Here is the code:
private void button3_Click(o bject sender, System.EventArg s 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.DataS ource = unit;
//comboBox1.Value Member = "id";
//comboBox1.Displ ayMember = "text";
}
private struct Unit
{
public string text;
public int id;
}
Comment