424,054 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,054 IT Pros & Developers. It's quick & easy.

Changing how a ListBox displays an object.

P: n/a
Hi all,

I have a System.Windows.Forms.ListBox object that I am putting objects into.
These objects are of custom types that I am defining. The list box displays
each object by its class name -- not exactly usable :). So what I would like
is to control the text that is displayed. Apparently, overridding the
ToString method does not work. So what is the trick?

I know that in Java, you can simply create a custom renderer that will
control how an object is displayed. Is there a similar thing in C#?

Dave.
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
quoting from MSDN
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfSystemWindows
FormsListBoxClassTopic.htm

"When an object is being added to the ListBox, the control uses the text
defined in the ToString method of the object unless a member name within the
object is specified in the DisplayMember property. In addition to adding
items using the Add method of the ListBox.ObjectCollection class you can
also add items using the DataSource property of the ListControl class."

Rakesh Ravuri
"Dave Rudolf" <da****************@hotmail.com> wrote in message
news:vo************@corp.supernews.com...
Hi all,

I have a System.Windows.Forms.ListBox object that I am putting objects into. These objects are of custom types that I am defining. The list box displays each object by its class name -- not exactly usable :). So what I would like is to control the text that is displayed. Apparently, overridding the
ToString method does not work. So what is the trick?

I know that in Java, you can simply create a custom renderer that will
control how an object is displayed. Is there a similar thing in C#?

Dave.

Nov 15 '05 #2

P: n/a
On Sun, 5 Oct 2003 15:38:25 -0600, "Dave Rudolf"
<da****************@hotmail.com> wrote:
Hi all,

I have a System.Windows.Forms.ListBox object that I am putting objects into.
These objects are of custom types that I am defining. The list box displays
each object by its class name -- not exactly usable :). So what I would like
is to control the text that is displayed. Apparently, overridding the
ToString method does not work. So what is the trick?


Overriding the ToString method *does* work. Double-check your code.

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.