I have two objects: User and Client, both implements interface IMember
interface IMember
{
int Id { get; set; }
string Name { get; set; }
}
In a form I set ListBox data source:
myListBox.DisplayMember = "Name";
myListBox.ValueMember = "Id";
myListBox.DataSource = membersList; // List<IMember>
And wierd things happen 😉 When I run program the first object, whichis type of User, displays correctly (Adrian Serafin) and other objects, wich are type of Contact are displayed like this:
MyProject.Client#20
MyProject.Client#40
as for display was ToString() call on them.
I can’t using list of different objects implementing the same interface as datasource in ListBox or I made some mistake here?
Are you sure it is
List<IMember>, and notArrayList? This makes a big difference, as the existence of a non-objectpublic indexer (public SomeType this[int] {get;set;}) makes a big difference. The following works fine: