I have a list of classes, but different children have different properties that need to be displayed.
What I want to achieve is to have a listbox-type control in the gui which enables each child to display it’s properties the way it wants to – so not using the same pre-defined columns for every class.
I envisage something like the transmission interface (below), where each class can paint it’s own entry, showing some text, progress bar if relevant, etc.

How can this be achieved in C#?
Thanks for any help.
Let your list items implement an interface that provides everything needed for the display:
The transmission objects should not display themselves. You should not mix domain logic (business logic) and display logic.
Customized ListBox:
In order to do display listbox items your own way, you will have to derive your own listbox control from
System.Windows.Forms.ListBox. Set theDrawModeproperty of your listbox toDrawMode.OwnerDrawFixedorDrawMode.OwnerDrawVariable(if the items are not of the same size) in the constructor. If you useOwnerDrawVariablethen you will have to overrideOnMeasureItemas well, in order to tell the listbox the size of each item.You can let your original transmission class implement
IDisplayItemor create a special class for this purpose. You can also have different types of objects in the list, as long as they implement the interface. The point is, that the display logic itself is in the control, the transmission class (or whatever class) only provides the information required.Example:
Because of the ongoing discussion with Mark, I have decided to include a full example here. Let’s define a model class:
Here is a custom ListBox:
On a form, we place this AddressListBox and a button. In the form, we place some initializing code and some button code, which changes our addresses. We do this in order to see, if our listbox is updated automatically:
When the button is clicked, the items in the AddressListBox are updated automatically. Note that only the DataSource of the listbox is defined. The DataMember and ValueMember remain empty.