E
EXdeveloper
Hi,
I'm using a ListBox to display objects of various classes. Most clases
are derived from a base class of mine. If I override ToString in these
classes, the listbox displays what I want.
BUT
I have another class that is derived from LinkedList.
Overriding ToString in this one does not give the expected result,
instead "(Collection)" is displayed in the ListBox.
(To clarify, writing out a string like
WriteLn("MyClass: " + myClassObj);
DOES give the expected result, so the ToString override is in place, it
is just not called when adding the object to the LB)
I can get around this by using the DisplayMember property, but it
annoys me that ToString works for some classes but not for others.
So, is there a reason why overriding ToString in
MyClass : LinkedList<Something> seems to do nothing when adding it to
the ListBox?
Thanks,
Mac
I'm using a ListBox to display objects of various classes. Most clases
are derived from a base class of mine. If I override ToString in these
classes, the listbox displays what I want.
BUT
I have another class that is derived from LinkedList.
Overriding ToString in this one does not give the expected result,
instead "(Collection)" is displayed in the ListBox.
(To clarify, writing out a string like
WriteLn("MyClass: " + myClassObj);
DOES give the expected result, so the ToString override is in place, it
is just not called when adding the object to the LB)
I can get around this by using the DisplayMember property, but it
annoys me that ToString works for some classes but not for others.
So, is there a reason why overriding ToString in
MyClass : LinkedList<Something> seems to do nothing when adding it to
the ListBox?
Thanks,
Mac