Results 1 to 25 of 25

Thread: [RESOLVED] Loading GrandChildNodes from DB

Threaded View

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] Loading GrandChildNodes from DB

    I had a lot of help here to get this sorted out with Parent and child nodes.

    I am now after loading GrandChildNodes to the tree. These will be the actual files, when clicked on, that open in a RTB
    It would be straight forward, but some of the Parent Nodes have Child Nodes, so to add a GrandChild Node, I could probably work out.
    But Some of the Parent Nodes don't have Child Nodes.

    I have attached a Pic of my DB Layout and also the treeview in my App.

    How do I code to add a GrandChild node to all parent nodes?

    As you will see in the TreeView pic, VBA has two child nodes, where as APi has no child node.

    Here is my code so far:
    vb Code:
    1. '==============================================================================================
    2. 'Load treeview nodes from DB
    3. 'Load arrays holding the names of the 'Parents' and the 'Children' nodes
    4. 'Also load 'NodesKey' array to use later to open the TV with the option saved in the Registry
    5. '==============================================================================================
    6.  
    7. With tvwCode
    8.     Do While Not rs.EOF
    9.         'check if node is same or different
    10.         If strNodeParent <> rs.Fields("tvwNodes").Value Then
    11.             'if different, it's a new parent node
    12.             strNodeParent = rs.Fields("tvwNodes").Value
    13.             'add 1 to the key
    14.             lngNodeParent = lngNodeParent + 1
    15.             'update key number if previous Parent node had children
    16.             If lngNodeParent <= lngNodeChild Then lngNodeParent = lngNodeChild + 1
    17.             'add the new node, with the new key and it's name
    18.             .Nodes.Add , , "P" & CStr(lngNodeParent), strNodeParent, "Folder Closed"
    19.             If PCtr = 0 Then
    20.                 strParent(PCtr) = strNodeParent
    21.                 NodesKey(KeyCtr) = strNodeParent & " P" & CStr(lngNodeParent)
    22.                 PCtr = PCtr + 1
    23.                 KeyCtr = KeyCtr + 1
    24.             Else
    25.                 ReDim Preserve strParent(UBound(strParent) + 1)
    26.                 strParent(PCtr) = strNodeParent
    27.                 ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    28.                 NodesKey(KeyCtr) = strNodeParent & " P" & CStr(lngNodeParent)
    29.                 PCtr = PCtr + 1
    30.                 KeyCtr = KeyCtr + 1
    31.             End If
    32.         End If
    33.  
    34.         'if needed, add the child
    35.         'check if there are any child nodes -
    36.         'if Fields is "" then no new child nodes
    37.         'move on to next parent node
    38.         If strNodeChild <> rs.Fields("tvwChildNodes").Value & "" Then
    39.             'if Fields is not empty - add new child node
    40.             strNodeChild = rs.Fields("tvwChildNodes").Value & ""
    41.                 If strNodeChild <> "" Then  '(dont add Null/blank child nodes)
    42.                     'add 1 to the key
    43.                     lngNodeChild = lngNodeChild + 1
    44.                     'if necessary add 1 to make number unique
    45.                     If lngNodeChild <= lngNodeParent Then lngNodeChild = lngNodeParent + 1
    46.                     'add the new child node with the path of the parent node
    47.                     .Nodes.Add "P" & CStr(lngNodeParent), tvwChild, "C" & CStr(lngNodeChild), strNodeChild, "Folder Closed"
    48.                     If CCtr = 0 Then
    49.                         strChild(CCtr) = strNodeParent & " " & strNodeChild
    50.                         If KeyCtr > 0 Then
    51.                             ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    52.                             NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    53.                             KeyCtr = KeyCtr + 1
    54.                         Else
    55.                             NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    56.                             KeyCtr = KeyCtr + 1
    57.                         End If
    58.                         CCtr = CCtr + 1
    59.                     Else
    60.                         ReDim Preserve strChild(UBound(strChild) + 1)
    61.                         strChild(CCtr) = strNodeParent & " " & strNodeChild
    62.                         ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    63.                         NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    64.                         CCtr = CCtr + 1
    65.                         KeyCtr = KeyCtr + 1
    66.                     End If
    67.                 End If
    68.         End If
    Attached Images Attached Images   
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

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