I am writing a winforms app in which a user selects an item from a listbox and edits some data that forms part of an associated object. The edits are then applied from the o
Try grabbing the "ValueMember" from within the ListBox1_SelectedValueChanged event.
private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (ListBox1.SelectedIndex != -1)
{
string orbit = ListBox1.SelectedValue.ToString();
}
}
ArrayList planets = new ArrayList();
planets.Add(new Planet("Mercury", "1"));
planets.Add(new Planet("Venus", "2"));
//Remember to set the Datasource
ListBox1.DataSource = planets;
//Name and Orbit are properties of the 'Planet' class
ListBox1.DisplayMember = "Name";
ListBox1.ValueMember = "Orbit";