|
-
Jan 17th, 2004, 01:23 PM
#1
Thread Starter
PowerPoster
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.
-
Jan 17th, 2004, 01:26 PM
#2
Thread Starter
PowerPoster
Just to let you know, this is the code I have found so far...
VB Code:
Private mWidgets(42) As Widget
Public Property Widgets(ByVal i As Integer) As Widget
Get
Return mWidgets(i)
End Get
Set(ByVal value As Widget)
mWidgets(i) = value
End Set
End Property
-
Jan 17th, 2004, 02:22 PM
#3
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:
Public Class State
Dim _Items as New CityCollection
Public ReadOnly Property Cities() As CityCollection
Get
Return _Items
End Get
End Property
End Class
Public Class City
Public Name As String
End Class
Public Class CityCollection
Inherits CollectionBase
Public Property Items(ByVal index As Integer) As City
Get
Return MyBase.InnerList(index)
End Get
Set(ByVal value As City)
MyBase.InnerList(index) = value
End Set
End Property
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.
-
Jan 18th, 2004, 02:14 AM
#4
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|