473,396 Members | 1,875 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,396 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 5769
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.