ToString Property for user-defined class/object

V

Vilem Sova

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
 
J

Jay B. Harlow [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top