ListBox - is the a reason this doesn't work?

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
 
L

Lloyd Dupont

I guess it's just ListBox which behave differently for collection
sorry no solution....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top