473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Changing how a ListBox displays an object.

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
2 5770
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
0
by: Dave Rudolf | last post by:
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 --...
2
by: Peteroid | last post by:
I'm going to be using a ListBox in my managed C++ application, and have a question. Why are the Items you Add to a ListBox in the form of generic Object*'s? I believe a ListBox displays a table of...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
2
by: bflyrose | last post by:
Hi I need some help I am trying to connect my radio buttons to show prices in the listbox with the name of the movie selected this is what I have so far my problem is I don't know how to get the...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
7
by: EManning | last post by:
I'm using A2003 connected to a SQL 2000 backend. This is not an adp. I have a table which I store 0 and -1 for 2 bit fields. I have a listbox on a form based on a query of this table. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.