By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

ToString Property for user-defined class/object

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.