|
-
Mar 31st, 2005, 11:12 AM
#1
Thread Starter
Hyperactive Member
get Parent value from Child
I use the Parent property in the TreeNode often to find the Text of the Parent of a particular TreeNode in a TreeView. Is it possible to mimic this functionality with a custom class.
I have a class called clsSummary and it contains a collection of classes called colDetail whilch is based on a class called clsDetail. Is there a way to access a value in the parent (clsSummary) from the child (clsDetail)? Any suggestions are appreciated.
clsDetail.Quantity = clsDetail.Parent.Quantity
-
Mar 31st, 2005, 12:13 PM
#2
Thread Starter
Hyperactive Member
Re: get Parent value from Child
So...
clsSummary contains a collection of class clsDetail.
I added another object to the clsDetail class of type clsSummary.
When I add a clsDetail to the clsSummay.colDetail collection I set the value for the "parent" so I can reference it like:
clsDetail.clsSummary.Quantity = 0
Is that wastefull? It should just be a reference to a place in memory right? So I'm not storing duplicate information... Some feedback would really be appreciated. If I've been unclear let me know.
-
Apr 1st, 2005, 09:22 AM
#3
Thread Starter
Hyperactive Member
Re: get Parent value from Child
Here is some code...
Is it ok for a child to have a copy of the Parent?
It seems like this is circular reference...
VB Code:
Private Class clsSummary
Public Property Quantity As Integer
Public Property Detail As clsDetail ' [Actually a collection in my code]
End Class
Private Class clsDetail
Public Property Quantity As Integer
Public Property Parent As clsSummary ' <-- Reference to Parent class...
End Class
-
Apr 1st, 2005, 09:48 AM
#4
Fanatic Member
Re: get Parent value from Child
The .NET Framework has circular references in it...so it must work. And yeah, you're not making a copy of the data, it's just a referene.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
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
|