First I have a Listbox and set the DataSource to a MyObjectCollection
MyObjectCollection implements the Interface IListSource wich contains MyObject’s
MyObject has the method
public override string ToString()
{
return "test";
}
The Listbox now displays “test” for each element in the MyObjectCollection.
But if I apply the IListSource interface to MyObject, too. The Listbox shows an empty string. How to fix that in the “MyObject” class.
A workaround is to fix it in the Listbox Format event, but than every GUI element has to implement this workaround :/
Generally, things should either be lists, or should be an entity for binding. If it is a list (
IListorIListSource) then much of the data-binding API will assume you actually want (for simple-binding scenarios, i.e. one row) the first item from the sublist.I would simply change it so that
MyObjectdoesn’t implementIListSource, but encapsulates it, perhaps exposing it via aItemsproperty. You could also look at whether a customTypeConverterwould work (I’ll investigate…)