...
IList items = Model.GetItems();
combo.DataSource = items;
combo.DisplayMember = "Name";
...
public class Model {
...
public static IList GetItems() {
ArrayList items = new ArrayList();
// Create and add items that implement IMyInterface
return items;
}
}
public interface IMyInterface {
string Name {get;}
}
This code, when bound to the combo box, works just fine for the first item, and displays the Name property just as it should. However, every subsequent item instead ignores the DisplayMember property and spits out the result of item.ToString().
How did I fix it? In the Model.GetItems() method, instead of placing the items in an ArrayList, I created an IMyInterface[] array. Now it works like a charm, and I'm left wondering why.