Results 1 to 4 of 4

Thread: Need help exposing a collection of objects as a property

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Need help exposing a collection of objects as a property

    Does anyone have any code that does this?

    I have a parent object, that needs to expose a collection of child objects.

    So, this seems all well and good, but I am finding it difficult to find some code to get me started.

    I basically need it to function like the dataset class. It is the parent class, that can hold table objects. I will then have to make it bindable so I will be implementing the IList interface.

    If anyone has done this, the proper way, I would appreciate any help.

  2. #2

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Just to let you know, this is the code I have found so far...

    VB Code:
    1. Private mWidgets(42) As Widget
    2.  
    3. Public Property Widgets(ByVal i As Integer) As Widget
    4.    Get
    5.       Return mWidgets(i)
    6.    End Get
    7.    Set(ByVal value As Widget)
    8.       mWidgets(i) = value
    9.    End Set
    10. End Property

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I'm not sure I understand what you are trying, but I would make Three objects, The Controller (Parent), the Detail (Child), the Collection (Strongly Typed Collection of Child). Then you'd expose the collection via a readonly property of type collection (strongly typed).
    VB Code:
    1. Public Class State
    2.  
    3.    Dim _Items as New CityCollection
    4.  
    5.    Public ReadOnly Property Cities() As CityCollection
    6.    Get
    7.       Return _Items
    8.    End Get
    9. End Property
    10.  
    11. End Class
    12.  
    13. Public Class City
    14.  
    15.    Public Name As String
    16.  
    17. End Class
    18.  
    19. Public Class CityCollection
    20.    Inherits CollectionBase
    21.  
    22.    Public Property Items(ByVal index As Integer) As City
    23.    Get
    24.       Return MyBase.InnerList(index)
    25.    End Get
    26.    Set(ByVal value As City)
    27.       MyBase.InnerList(index) = value
    28.    End Set
    29.    End Property
    30.  
    31. End Class

    Its a bit more code but it works in a good structure and makes the pieces more independant and binding may be easier.

  4. #4

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Thanks. I will look into how that will fit into what we are doing and see which would be better.

    The basic need here is to create a object heirarchy that represents rows in multiple related tables in the database, and allow the UI code to bind to the objects.

    We are trying to move away from the quick and dirty app dev into fully OO applications whenever we can.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width