473,386 Members | 1,668 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,386 software developers and data experts.

ToString Property for user-defined class/object

I want to use a user-defined object in the 'Add' method to add items to a
combo box. The help documentation says that if you use an object in the add
method then the object's 'ToString' method is used to obtain the string to
display in the combo box.

I've added a public property "ToString" to my object that contains the
required text to display, but it is not being called to get the required
text. The text that is appearing in the combo box list is
ProjectName.ObjectName for every item in the list.

So how do I create the "ToString" property so that it's called by 'Add'
method of a combo box?

Thanks
Vilem Sova
Nov 21 '05 #1
1 1540
Vilem,
So how do I create the "ToString" property so that it's called by 'Add'
method of a combo box? You don't, you need to override the ToString Function in your class.

Something like:

Public Class UserDefined

Private m_value As String

Public Sub New(value As String)
m_value = value
End Sub

Public Overrides Function ToString() As String
Return m_value
End Function

End Public

Hope this helps
Jay

"Vilem Sova" <vs***@austarmetro.com.au> wrote in message
news:uG**************@TK2MSFTNGP15.phx.gbl...I want to use a user-defined object in the 'Add' method to add items to a
combo box. The help documentation says that if you use an object in the
add
method then the object's 'ToString' method is used to obtain the string to
display in the combo box.

I've added a public property "ToString" to my object that contains the
required text to display, but it is not being called to get the required
text. The text that is appearing in the combo box list is
ProjectName.ObjectName for every item in the list.

So how do I create the "ToString" property so that it's called by 'Add'
method of a combo box?

Thanks
Vilem Sova

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Suresh | last post by:
Hi, I need to add a custom ToString method on an Enum Property. The default ToString method expands the whole name. But, I want only an short associated code with the long name of the enum type....
4
by: Krish | last post by:
I donot understand why it is this way. I have an arraylist. I understand I can get the count by arraylist.count in .net studio, intellisense also gives me arraylist.count.tostring()
1
by: Steven.Xu | last post by:
Hi, everyone. I am writting an user control. There has some properties on it. At the design time, the properties will disply on the property windows and user could change it's value after selected...
10
by: | last post by:
I have a property where I want to associate tostring with it. So that this would be valid: ----- Dim x as string x = myobject.myproperty.tostring ----- I know I have to overide...
2
by: Anastasios Papadopoulos | last post by:
Hello all, I have statements like the following in my Property Get: Public Property AccountNumber() As String Get Return MyClass.AccountNumber.ToString End Get blah blah End Property
2
by: archana | last post by:
Hi all, I am facing some wired problem while using above mention data type. What i am doing is i am writing DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +...
8
by: Phil Jollans | last post by:
Hi, I am having difficulty overriding the ToString() method of CultureInfo using Visual Studio 2005. Exactly the same code works fine with Visual Studio .NET 2003. What I am doing is adding...
3
by: Paul | last post by:
I have two properties in a user control of mine. One is FormatValue which the user can select Currency, Number, etc. The second is NumberOfDecimalPlaces. When the user chooses Currency, I want...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
38
by: tshad | last post by:
In VS 2008, why doesn't ToString require "()". If I have Option Strict On on why can I do both: selectedIndex.ToString() selectedIndex.ToString or sQuery =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.