Here's another one. The code is below.
If I display to the ListBox, I get the exception:
Could not bind to the new display member, Parameter name:
newDisplayMember
and all ListBox members are set to MtProg.Form1.USState
If I comment out the listBox1 lines, leaving the comboBox1 lines, I get the
same exception but the combo box remains unchanged.
public class USState
{
public string longName;
public string shortName;
public USState(string shortName, string longName)
{
this.shortName=shortName;
this.longName=longName;
}
}
ArrayList USStates = new ArrayList();
private void button1_Click(object sender, System.EventArgs e)
{
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI"));
USStates.Add(new USState("Wyoming", "WY"));
listBox1.DataSource = USStates;
listBox1.DisplayMember = "longName";
listBox1.ValueMember = "shortName";
comboBox1.DataSource = USStates;
comboBox1.DisplayMember = "longName";
comboBox1.ValueMember = "shortName";
}