I have these classes:
public class City {
public string name { get; set; }
public override string ToString() { return name; }
}
public List<City> cities = new List();
public class Person {
public string name { get; set; }
public string addr { get; set; }
public City city { get; set; }
}
List<Person> persons;
I bind cities and persons to bindingSource
(and to list and textbox):
bindingSource_city.DataSource = cities;
textBox1.DataBindings.Add("Text", bindingSource_city, "name");
bindingSource_person.DataSource = person;
textBox2.DataBindings.Add("Text", bindingSource_person, "name");
textBox3.DataBindings.Add("Text", bindingSource_person, "addr");
also listBox.DataSource = bindingSource
(in form editor).
All seems to work fine. How can I create combobox with cities in list and binded to person.city property? I cant understand how to fill drop-down list with objects (not string items).
EDIT: Or how to convert person.city to SelectedIndex
on data (list index) change and back.