As I become more "object oriented" in my development approach (I've done VB for too long) I was struggling to get ComboBoxes and ListBoxes to accept and display an object appropriately rather than just populating the list with a string, and then using an index or string lookup to find the appropriate item.The other day I had a sniff around the internet and thought that the Format event might help, and today I managed to get it to work. If I have a combobox called myList, and I've assigned a Person object to it as
myList.Items.Add(person). I then need to register the event Format as:private void myList_Format(object sender, ListControlConvertEventArgs e)
e.value = ((Person)e.ListItem).Surname;
}myList will then be populate with the Surname of the Person, but the myList.SelectedItem will hold the object currently selected.
comments powered by