Steve,
Are you putting a "Public Overrides Function ToString() As String" in your
class?
The following should work:
Option Strict On
Public Class MyItem
Private ReadOnly m_text As String
Public Sub New(ByVal text As String)
m_text = text
End Sub
Public Overrides Function ToString() As String
Return m_text
End Function
...
End Class
Then within your Form, you need something like:
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
With ListBox1.Items
.Add(New MyItem("item 1"))
.Add(New MyItem("item 2"))
.Add(New MyItem("item 3"))
.Add(New MyItem("item 4"))
.Add(New MyItem("item 5"))
End With
End Sub
Note that you need to include the "As String" on the function otherwise
VB.NET will assume As Object, which is not at all what you want. Also the
Option Strict On, will help ensure that you include the type on the
Function.
Hope this helps
Jay
"steve" <a@b.com> wrote in message
news:10*************@corp.supernews.com...
i'm trying to create an item to be added to a listbox. reason being is
that the "item" has properties i need to access when it is selected. i'm having
trouble displaying it in the list though. i've tried putting a public
overrides function ToString() and a public shadows function ToString() as
one of its interfaces so that the listbox knows what text to display. the
items should simply be diplaying either an item number and/or description
based on other properties of my item.
where have i gone wrong?
tia,
steve