Results 1 to 4 of 4

Thread: get Parent value from Child

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489

    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

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489

    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:
    1. Private Class clsSummary
    2.     Public Property Quantity As Integer
    3.     Public Property Detail As clsDetail ' [Actually a collection in my code]
    4. End Class
    5. Private Class clsDetail
    6.     Public Property Quantity As Integer
    7.     Public Property Parent As clsSummary ' <-- Reference to Parent class...
    8. End Class

  4. #4
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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
  •  



Click Here to Expand Forum to Full Width