3 Replies - 778 Views - Last Post: 11 May 2010 - 06:39 PM Rate Topic: -----

#1 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

List Box Display issue

Posted 11 May 2010 - 04:10 PM

I have a listbox and i add an object to the listbox
 For Each dr As DataRow In tempTab.Rows
            tempListBoxObject = New classListJobsItems(dr.Item(0), dr.Item(1), dr.Item(2), dr.Item(3), dr.Item(4), dr.Item(5), dr.Item(6), dr.Item(7))
          
  lstJobTitles.Items.Add(tempListBoxObject)
            lstJobTitles.DisplayMember = tempListBoxObject.Title.ToString

        Next



title is just a read only property returning a string

Public ReadOnly Property Title() As String
        Get
            Return mJobTitle
        End Get
    End Property



so i think it looks fine but the output in the list box is the name of my project and class

JobsProject.classListjobsitems



What am i doing wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: List Box Display issue

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: List Box Display issue

Posted 11 May 2010 - 05:09 PM

If I remember correctly...
When adding a class object to a listbox be sure to override the ToString method in the class object and return the Title property and it will display this.
Was This Post Helpful? 1
  • +
  • -

#3 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

Re: List Box Display issue

Posted 11 May 2010 - 05:42 PM

Wicked! Thanks.

Is this because unless i override the tostring method my object is inheriting the default object tostring method automatically?

So even though i specify it, when my object is returning the title property, it is using the default object tostring?
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: List Box Display issue

Posted 11 May 2010 - 06:39 PM

Without overriding it you will get the object's type name or it's ToString method.

This post has been edited by hawkvalley1: 11 May 2010 - 06:59 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1