Home All Groups Group Topic Archive Search About

Custom Collections : overriding toString

Author
14 Apr 2005 4:23 PM
ECathell
I am having issues with my collection now that i have it mostly together. I am binding it to a listbox, but instead of the box information I want it to show, it is simply showing the object type. I have tried overriding it with the following.


Public Overrides Function toString() As String
            Dim result As System.Text.StringBuilder
            Dim item As Box
            For Each item In Me.List
                result.Append(item.BoxType.ToString)
            Next
        End Function


I found something similar to that on the net and modified it for how I think it should work. But its still not working...any ideas?
--
--Eric Cathell, MCSA

Author
14 Apr 2005 4:50 PM
Charlie
Have you set the "DisplayMember" property of the ListBox to the property of
the collection you want to show?  The default member in a standard collection
is "Item", and when using a standard collection you do not have to set
"DisplayMember", but maybe you have altered the properties, and will have to
point the ListBox in the right direction.

Show quoteHide quote
"ECathell" wrote:

> I am having issues with my collection now that i have it mostly together. I am binding it to a listbox, but instead of the box information I want it to show, it is simply showing the object type. I have tried overriding it with the following.
>
>
> Public Overrides Function toString() As String
>             Dim result As System.Text.StringBuilder
>             Dim item As Box
>             For Each item In Me.List
>                 result.Append(item.BoxType.ToString)
>             Next
>         End Function
>
>
> I found something similar to that on the net and modified it for how I think it should work. But its still not working...any ideas?
> --
> --Eric Cathell, MCSA
Author
14 Apr 2005 7:00 PM
Larry Lard
ECathell wrote:
> I am having issues with my collection now that i have it mostly
together. I am binding it to a listbox, but instead of the box
information I want it to show, it is simply showing the object type. I
have tried overriding it with the following.
>
>
> Public Overrides Function toString() As String
>             Dim result As System.Text.StringBuilder
>             Dim item As Box
>             For Each item In Me.List
>                 result.Append(item.BoxType.ToString)
>             Next
>         End Function
>
>
> I found something similar to that on the net and modified it for how
I think it should work. But its still not working...any ideas?

Umm... Return result.ToString ?

--
Larry Lard
Replies to group please
Author
14 Apr 2005 7:28 PM
ECathell
I figured it out. I think it may have been a pretty silly error. I was trying to override the toString function in my collection class to return the name of the object. I had to Override the toString Method in my COLLECTED class to return the information I wanted displayed.

Thanks to dave Hayden at http://codebetter.com/blogs/david.hayden/archive/2005/02/24/55984.aspx for knocking me upside my head.



--
--Eric Cathell, MCSA
  "ECathell" <ecathell@nospam.mountaire.com> wrote in message news:eEAD74QQFHA.2136@TK2MSFTNGP14.phx.gbl...
  I am having issues with my collection now that i have it mostly together. I am binding it to a listbox, but instead of the box information I want it to show, it is simply showing the object type. I have tried overriding it with the following.


  Public Overrides Function toString() As String
              Dim result As System.Text.StringBuilder
              Dim item As Box
              For Each item In Me.List
                  result.Append(item.BoxType.ToString)
              Next
          End Function


  I found something similar to that on the net and modified it for how I think it should work. But its still not working...any ideas?
  --
  --Eric Cathell, MCSA