PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Loading GrandChildNodes from DB-VBForums
Results 1 to 25 of 25

Thread: [RESOLVED] Loading GrandChildNodes from DB

  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

  2. #2

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

    Re: Loading GrandChildNodes from DB

    Ok, slowly, but surely I am getting there

    I have added the following code, and I am almost there:
    vb Code:
    1. If strNodeGrandChild <> rs.Fields("tvwGrandChildNodes").Value & "" Then
    2.             'if Fields is not empty - add new grandchild node
    3.             strNodeGrandChild = rs.Fields("tvwGrandChildNodes").Value & ""
    4.             .Nodes.Add strNodeParent, strNodeChild, , strNodeGrandChild, "Leaf"
    5.         End If

    strNodeParent = VB Code
    strNodeChild = Functions
    strNodeGrandChild = Change Text Case

    So all values are as expected, but I am getting the error:
    Element not found
    on the .Nodes.Add line.

    I have tried using tvwLast, tvwNext
    but these don't work, or at least not the way I am using them.

    I know this is the problem but I'm not sure what to change.
    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

  3. #3

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

    Re: Loading GrandChildNodes from DB

    Right, with this code, added after the Childnodes are added, I am now getting what is shown in the image, but I am now stumped.

    There should only be 2 entries, not a third empty one, and they are supposed to be the next level in!

    vb Code:
    1. 'if no Child node, is there a grandchild node
    2.         If strNodeChild = "" Then
    3.             If strNodeGrandChild <> rs.Fields("tvwGrandChildNodes").Value & "" Then
    4.                 'if Fields is not empty - add new grandchild node
    5.                 strNodeGrandChild = rs.Fields("tvwGrandChildNodes").Value & ""
    6.                 .Nodes.Add "P" & CStr(lngNodeParent), tvwLast, , strNodeGrandChild, "Leaf"
    7.             End If
    8.         Else
    9.             If strNodeGrandChild <> rs.Fields("tvwGrandChildNodes").Value & "" Then
    10.                 'if Fields is not empty - add new grandchild node
    11.                 strNodeGrandChild = rs.Fields("tvwGrandChildNodes").Value & ""
    12.                 .Nodes.Add "C" & CStr(lngNodeChild), tvwLast, , strNodeGrandChild, "Leaf"
    13.             End If
    14.         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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: Loading GrandChildNodes from DB

    You are currently adding to the Parent ("P" & CStr(lngNodeParent)) in some cases, but should always be adding to the Child ("C" & CStr(lngNodeChild)).

    You should also be checking that rs.Fields("tvwGrandChildNodes").Value is not blank

  5. #5

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

    Re: Loading GrandChildNodes from DB

    Thanks si

    Quote Originally Posted by si_the_geek
    You are currently adding to the Parent ("P" & CStr(lngNodeParent)) in some cases, but should always be adding to the Child ("C" & CStr(lngNodeChild)).
    Sorry here si, I think I am missing something Now that may surprise you

    If the parent has no child, I though I would be adding it to a parent, where as if it has a child, I though I would be adding it to that child.

    Quote Originally Posted by si_the_geek
    You should also be checking that rs.Fields("tvwGrandChildNodes").Value is not blank
    I though that what you showed me in an earlier post, by adding the [& " "] made sure it wasn't blank, but an empty string.

    Or am I missing something else again.

    It's late now, so I think I will come back to this tomorrow.
    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

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: Loading GrandChildNodes from DB

    Quote Originally Posted by aikidokid
    If the parent has no child, I though I would be adding it to a parent, where as if it has a child, I though I would be adding it to that child.
    Nope.. the grandchild is a "child" of an existing child. You cannot have a gap between the parent and their grandchild.

    I'm pretty sure you should be using tvwChild instead of tvwLast

    I though that what you showed me in an earlier post, by adding the [& " "] made sure it wasn't blank, but an empty string.
    That is for treating Null's as if they are empty strings.. but ignore that bit of my post, as you already have the If statement you need!

  7. #7

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

    Re: Loading GrandChildNodes from DB

    Quote Originally Posted by si_the_geek
    Nope.. the grandchild is a "child" of an existing child. You cannot have a gap between the parent and their grandchild.
    Makes sense now.

    Quote Originally Posted by si
    I'm pretty sure you should be using tvwChild instead of tvwLast
    I am now, thanks, and it's working.


    OK, I have it working now with the following code:
    vb Code:
    1. If Not IsNull(rs.Fields("tvwGrandChildNodes")) Then
    2.             If strNodeGrandChild <> rs.Fields("tvwGrandChildNodes").Value & "" Then
    3.                            
    4.                 Debug.Print rs.Fields("tvwGrandChildNodes").Value & ""
    5.                 'if Fields is not empty - add new grandchild node
    6.                 strNodeGrandChild = rs.Fields("tvwGrandChildNodes").Value & ""
    7.                 .Nodes.Add "C" & CStr(lngNodeChild), tvwChild, , strNodeGrandChild, "Leaf"
    8.             End If
    9.         End If

    But, and there's always a but ....

    When you look in the DB_Fields.gif in Post#1, you can see the category API, Modules have no entries in the tvwChildNode field.

    So, when loading the Nodes, when I get to the part that checks to see if there are any entries in the tvwChildNodes field, would I then have to check if there was anything in the tvwGrandChildNode field and then add it before continuing with the loop to load the rest of the nodes.

    OR, will I have to save it differently? If so, how do I do this without creating an extra unnecessary level of nodes?

    Hope this makes some sort of sense?

    Why is nothing sraight forward in programming
    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

  8. #8

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

    Re: Loading GrandChildNodes from DB

    I have resolved this, although not 100% the way I would have liked to.

    As I know in advance what the categories are going to be, I have added a 'Select Case' statement to filter out the categories without the child node, then loaded the nodes this way.
    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

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: Loading GrandChildNodes from DB

    It doesn't really make sense to check the GrandChild if there is no Child, so the code could go between lines 67 and 68 of your original post.

    This does make it a bit more awkward in terms of adding Nodes, but to be honest I think you should deal with the actual Items (what you currently have in the GrandChild field) slightly differently. We should think about this tho, based on your current table design.

    What I think you should have in this table is just the Nodes, and the actual items (including their titles) stored in a separate table. An extra Number field would then be added to that table (called NodeID?), which specifies which 'folder' the item goes in - it would link to the AutoNumber field in this table, so "RemoveAmp" and "Change Text Case" would have a NodeID value of 14.

    If you do that, the ID's for the nodes would change from "P" & CStr(lngNodeParent) and "C" & CStr(lngNodeChild) to "N" & rs.Fields("AutoNumber").Value , and you would use a separate loop to add the items to the existing nodes.

    Doing this would be a better design, as it has less repeating data - but it could be confusing for you!


    The alternative is to keep what you've got, and after your existing new bit (between 67 and 68) add an Else clause (at the same level as the End If on line 68) with basically the same bit of code again - but this time adding to the Parent node instead of the Child.


    edit: your new idea isn't a great one.. if there is ever any change in the data (such as a change of spelling of a node), you will need to modify (and re-compile) the program, instead of just changing data in the database.
    Why is nothing straight forward in programming
    It is if you look at a small enough level.. the bigger picture gets easily complicated if you don't plan it in advance. Unfortunately I haven't helped there, I seem to have made things a bit worse!

  10. #10

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

    Re: Loading GrandChildNodes from DB

    First thinks first ....

    Quote Originally Posted by si_the_geek
    It is if you look at a small enough level.. the bigger picture gets easily complicated if you don't plan it in advance. Unfortunately I haven't helped there, I seem to have made things a bit worse!
    Far from it si, I am here to learn. My problem is I am just a bit too impatient.
    I have been doing programming in my own time, and learning with the help of this forum mainly, on and off for ages, and as of yet, I have yet to compile a program I have written.
    This one is the closest I have come and that is what is making me impatient.

    As for the DB, I can redesign this anyway needed.
    The code I have saved in it, is saved as text files, which is what I did originally.

    It's just as long as you guys are patient enough for me to catch up with what you are thinking (which everybody has been so far)


    Quote Originally Posted by si_the_geek
    What I think you should have in this table is just the Nodes, and the actual items (including their titles) stored in a separate table. An extra Number field would then be added to that table (called NodeID?), which specifies which 'folder' the item goes in - it would link to the AutoNumber field in this table, so "RemoveAmp" and "Change Text Case" would have a NodeID value of 14.

    If you do that, the ID's for the nodes would change from "P" & CStr(lngNodeParent) and "C" & CStr(lngNodeChild) to "N" & rs.Fields("AutoNumber").Value , and you would use a separate loop to add the items to the existing nodes.

    Doing this would be a better design, as it has less repeating data - but it could be confusing for you!
    This just shows how much I have to learn.
    I didn't think that the design of the DB would be so important, and also that it should be sorted out first!

    Quote Originally Posted by si_the_geek
    edit: your new idea isn't a great one.. if there is ever any change in the data (such as a change of spelling of a node), you will need to modify (and re-compile) the program, instead of just changing data in the database.
    I sort of new this

    I think I will go with the re-designing of the DB and go from their.

    I will get a couple of pics of the two tables I have so far and post them, and if you wouldn't mind, get some advice on how to change them for the better.
    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

  11. #11

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    OK, I have attached the two images of the two tables I have at present in my DB
    Obviously, tbl_Nodes stores the names of the nodes, the grandchild nodes being the actual files to open (Well for most of them anyway )
    tbl_Code is where the actual file is stored.
    After the comments in another thread, I may wall use this re-design to not use the name Code for the field, maybe fldCode or similar.

    vb Code:
    1. This is the code I ended up using, when I hard coded it :o :
    2. With tvwCode
    3.     .Nodes.Add , , "Source", "Source Code", "Folder Closed"
    4.     Do While Not rs.EOF
    5.         'check if node is same or different
    6.         If strNodeParent <> rs.Fields("tvwNodes").Value Then
    7.             'if different, it's a new parent node
    8.             strNodeParent = rs.Fields("tvwNodes").Value
    9.             'add 1 to the key
    10.             lngNodeParent = lngNodeParent + 1
    11.             'update key number if previous Parent node had children
    12.             If lngNodeParent <= lngNodeChild Then lngNodeParent = lngNodeChild + 1
    13.             'add the new node, with the new key and it's name
    14.             .Nodes.Add "Source", tvwChild, "P" & CStr(lngNodeParent), strNodeParent, "Folder Closed"
    15.             If PCtr = 0 Then
    16.                 strParent(PCtr) = strNodeParent
    17.                 NodesKey(KeyCtr) = strNodeParent & " P" & CStr(lngNodeParent)
    18.                 PCtr = PCtr + 1
    19.                 KeyCtr = KeyCtr + 1
    20.             Else
    21.                 ReDim Preserve strParent(UBound(strParent) + 1)
    22.                 strParent(PCtr) = strNodeParent
    23.                 ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    24.                 NodesKey(KeyCtr) = strNodeParent & " P" & CStr(lngNodeParent)
    25.                 PCtr = PCtr + 1
    26.                 KeyCtr = KeyCtr + 1
    27.             End If
    28.         End If
    29.  
    30.         'if needed, add the child
    31.         'check if there are any child nodes -
    32.         'if Fields is "" then no new child nodes
    33.         'move on to next parent node
    34.         Select Case rs!tvwnodes
    35.             Case Is = "API", "Modules", "SQL"
    36.                 If strNodeChild <> rs.Fields("tvwChildNodes").Value & "" Then
    37.                     'if Fields is not empty - add new child node
    38.                     strNodeChild = rs.Fields("tvwChildNodes").Value & ""
    39.                         If strNodeChild <> "" Then  '(dont add Null/blank child nodes)
    40.                             'add 1 to the key
    41.                             lngNodeChild = lngNodeChild + 1
    42.                             'if necessary add 1 to make number unique
    43.                             If lngNodeChild <= lngNodeParent Then lngNodeChild = lngNodeParent + 1
    44.                             'add the new child node with the path of the parent node
    45.                             .Nodes.Add "P" & CStr(lngNodeParent), tvwChild, "C" & CStr(lngNodeChild), strNodeChild, "Leaf"
    46.                             If CCtr = 0 Then
    47.                                 strChild(CCtr) = strNodeParent & " " & strNodeChild
    48.                                 If KeyCtr > 0 Then
    49.                                     ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    50.                                     NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    51.                                     KeyCtr = KeyCtr + 1
    52.                                 Else
    53.                                     NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    54.                                     KeyCtr = KeyCtr + 1
    55.                                 End If
    56.                                 CCtr = CCtr + 1
    57.                             Else
    58.                                 ReDim Preserve strChild(UBound(strChild) + 1)
    59.                                 strChild(CCtr) = strNodeParent & " " & strNodeChild
    60.                                 ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    61.                                 NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    62.                                 CCtr = CCtr + 1
    63.                                 KeyCtr = KeyCtr + 1
    64.                             End If
    65.                         End If
    66.                 End If
    67.             Case Else
    68.                 If strNodeChild <> rs.Fields("tvwChildNodes").Value & "" Then
    69.                     'if Fields is not empty - add new child node
    70.                     strNodeChild = rs.Fields("tvwChildNodes").Value & ""
    71.                         If strNodeChild <> "" Then  '(dont add Null/blank child nodes)
    72.                             'add 1 to the key
    73.                             lngNodeChild = lngNodeChild + 1
    74.                             'if necessary add 1 to make number unique
    75.                             If lngNodeChild <= lngNodeParent Then lngNodeChild = lngNodeParent + 1
    76.                             'add the new child node with the path of the parent node
    77.                             .Nodes.Add "P" & CStr(lngNodeParent), tvwChild, "C" & CStr(lngNodeChild), strNodeChild, "Folder Closed"
    78.                             If CCtr = 0 Then
    79.                                 strChild(CCtr) = strNodeParent & " " & strNodeChild
    80.                                 If KeyCtr > 0 Then
    81.                                     ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    82.                                     NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    83.                                     KeyCtr = KeyCtr + 1
    84.                                 Else
    85.                                     NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    86.                                     KeyCtr = KeyCtr + 1
    87.                                 End If
    88.                                 CCtr = CCtr + 1
    89.                             Else
    90.                                 ReDim Preserve strChild(UBound(strChild) + 1)
    91.                                 strChild(CCtr) = strNodeParent & " " & strNodeChild
    92.                                 ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    93.                                 NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
    94.                                 CCtr = CCtr + 1
    95.                                 KeyCtr = KeyCtr + 1
    96.                             End If
    97.                         End If
    98.                 End If
    99.             End Select
    100.        
    101.         '(grand-child is similar to child, but you dont need to store the text/key!)
    102.         If Not IsNull(rs.Fields("tvwGrandChildNodes")) Then
    103.             If strNodeGrandChild <> rs.Fields("tvwGrandChildNodes").Value & "" Then
    104.                 'if Fields is not empty - add new grandchild node
    105.                 strNodeGrandChild = rs.Fields("tvwGrandChildNodes").Value & ""
    106.                 .Nodes.Add "C" & CStr(lngNodeChild), tvwChild, , strNodeGrandChild, "Leaf"
    107.             End If
    108.         End If
    109.         rs.MoveNext
    110.     Loop
    111. End With
    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

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: [RESOLVED] Loading GrandChildNodes from DB

    The field name Code is actually valid, it's just one of those that looks like a reserved word, but it isn't.

    In tbl_Code I would have these fields:
    Code_ID - the AutoNumber field (I don't see a reason for your current Code_ID data)
    Code_Description - as it is
    Notes - as it is
    Code_Text - same as Code (just to avoid confusion over the field name!)
    Node_ID - link to the Nodes table

    In tbl_Nodes I would have these fields:
    Node_ID - the AutoNumber field
    NodeName - same as tvwNodes
    ChildNodeName - same as tvwChildNodes
    [GrandChildNodeName - if needed, an extra level of 'folders']

    In theory (but only in theory!) you would not have a "Child" or "GrandChild" field, but instead have a "ParentID" field link which links back to the same table.. this would mean less data is stored (eg: "VB Code" would only be stored once), but it makes the code (and the database itself) much more complex, so isn't worth the hassle!

  13. #13

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    I was almost finished this when you posted

    I have the tables as you suggested.

    tbl_Code:
    I have set the text and memo default value's to ""
    The Node_ID filed set to "number"

    tbl_Nodes:
    I have set the text default value's to ""
    The Node_ID field is set to autonumber

    Do I need to change the Indexed to "Yes (No Duplicates) for the Nodes and Code_Description fields?
    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

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: [RESOLVED] Loading GrandChildNodes from DB

    For the amount of data you have, there isn't much point in having indexes.

    If chosen carefully they make searching a 'big' table faster, but are very unlikely to provide any benefit here, as there aren't enough rows of data to make a difference.

    By setting it to "No Duplicates" it would mean that you couldn't have two items with the same name.. in tbl_Code this could be a problem, as it is perfectly valid to have two items with the same name, as long as they are under different nodes.

  15. #15

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Thanks si,

    I am getting to work on changing the code to load the nodes now.
    Just realised how much code else where I am probably going to have to change, in the save code and open code.

    Quote Originally Posted by si_the_geek
    If you do that, the ID's for the nodes would change from "P" & CStr(lngNodeParent) and "C" & CStr(lngNodeChild) to "N" & rs.Fields("AutoNumber").Value ,
    I've got this, I hope it is just that simple.

    Quote Originally Posted by si_the_geek
    What I think you should have in this table is just the Nodes
    So load this first:

    Source Code
    |____VB Code
    | |_____Functions
    |____Modules

    Quote Originally Posted by si_the_geek
    you would use a separate loop to add the items to the existing nodes.
    Not quite sure how to do this!

    When I add the new data to the DB, it would be something like this?

    Nodes_ID in the tbl_Nodes would be as follows:
    API = 1
    Modules = 2
    VB Code Functions = 3
    VB Code Subs = 4

    So when I add a new piece of code to the DB:

    tbl_Code - Node_ID would be the value of which ever node it is stored under, such as:
    mRegistry (Module) would have '2' stored in the Node_ID field.

    Then loop through the tbl_Code Node_ID field and would you load each entry as you go, or loop looking for any '1' and then any '2' etc?

    ALSO
    Would you have Modules as one of the Child nodes of VB?
    I have also decided to leave the 'Notes' node off of the treeview. It is accessed else where now.

    Sorry if it sounds obvious, but it ain't to me
    Last edited by aikidokid; Apr 2nd, 2007 at 12:37 PM. Reason: Added a question
    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

  16. #16

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Another question!

    Is the AutoNumber field also the Primary Key as well?
    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

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Quote Originally Posted by aikidokid
    When I add the new data to the DB, it would be something like this?
    ...
    Exactly.

    Then loop through the tbl_Code Node_ID field and would you load each entry as you go, or loop looking for any '1' and then any '2' etc?
    You would do similar to the current setup you have for adding nodes, except reading from the tbl_Code table, and simply adding every item directly to the node - using .Nodes.Add "N" & rs.Fields("NodeID").Value, tvwChild, ...

    Would you have Modules as one of the Child nodes of VB?
    It's completely up to you.. it's easy enough to change it later if you want (you just need to edit the Nodes table).

    Is the AutoNumber field also the Primary Key as well?
    Yep.

    The NodeID field in tbl_Code is a Foreign Key (links to a Primary Key of another table).

  18. #18

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    When adding new data to the DB, does the autonumber field automatically increase, you don't have to add to it?

    I have changed this as shown:
    Quote Originally Posted by si
    If you do that, the ID's for the nodes would change from "P" & CStr(lngNodeParent) and "C" & CStr(lngNodeChild) to "N" & rs.Fields("AutoNumber").Value
    so would this line
    vb Code:
    1. .Nodes.Add "P" & CStr(lngNodeParent), tvwChild, "C" & CStr(lngNodeChild), strNodeChild, "Folder Closed"
    now become
    vb Code:
    1. .Nodes.Add "N" & rs.Fields("AutoNumber").Value, tvwChild, "N" & rs.Fields("AutoNumber").Value, strNodeChild, "Folder Closed"
    or
    vb Code:
    1. .Nodes.Add "N" & rs.Fields("AutoNumber").Value, tvwChild,  strNodeChild, "Folder Closed"

    Because on this line I am now getting the error:
    Item cannot be found in the collection corresponding to the name or ordinal

    on this line- this part - "N" & rs.Fields("AutoNumber").Value
    vb Code:
    1. With tvwCode
    2.     .Nodes.Add , , "Source", "Source Code", "Folder Closed"
    3.     Do While Not rs.EOF
    4.         'check if node is same or different
    5.         If strNodeParent <> rs.Fields("NodeName").Value Then
    6.             'if different, it's a new parent node
    7.             strNodeParent = rs.Fields("NodeName").Value
    8.             'add 1 to the key
    9.             lngNodeParent = lngNodeParent + 1
    10.             'update key number if previous Parent node had children
    11.             If lngNodeParent <= lngNodeChild Then lngNodeParent = lngNodeChild + 1
    12.             'add the new node, with the new key and it's name
    13.             .Nodes.Add "Source", tvwChild, [U]"N" & rs.Fields("AutoNumber").Value[/U], strNodeParent, "Folder Closed"

    Do I still need to use these now I am using the AutoNumber field:
    vb Code:
    1. 'add 1 to the key
    2.  lngNodeParent = lngNodeParent + 1
    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

  19. #19
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Ah, I hadn't thought about that bit!

    First of all I'd recommend changing the field names from AutoNumber (to NodeID etc), as it will make things easier to read.

    For the Parent it should be added as you have it in the first post (but with the N change).

    You don't actually need the lngNodeParent/lngNodeChild variables any more, but should instead be storing the N value (including the field value) to a variable instead. Note that if you don't have grandchild nodes, you wont need to store it for the child nodes.

    You would then use that variable as the first parameter when adding the child nodes.

  20. #20

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Quote Originally Posted by si_the_geek
    First of all I'd recommend changing the field names from AutoNumber (to NodeID etc), as it will make things easier to read.
    Done.

    Quote Originally Posted by si_the_geek
    For the Parent it should be added as you have it in the first post (but with the N change).
    Done, with the "N" change.

    Quote Originally Posted by si_the_geek_
    You don't actually need the lngNodeParent/lngNodeChild variables any more, but should instead be storing the N value (including the field value) to a variable instead. Note that if you don't have grandchild nodes, you wont need to store it for the child nodes.
    So what I have done here is to save into the new variable the following:
    API=N22
    VB Code=N23
    etc

    Is this what you meant?
    I put the '=' in so, if needed, string manipulation would be easier, regardless of how many items added to the array.

    Quote Originally Posted by si_the_geek
    You would then use that variable as the first parameter when adding the child nodes.
    Wouldn't what I almost already had do this:

    vb Code:
    1. .Nodes.Add "N" & rs.Fields("Node_ID").Value, tvwChild, "N" & rs.Fields("Node_ID").Value, strNodeChild, "Folder Closed"

    Quote Originally Posted by si_the_geek
    Note that if you don't have grandchild nodes, you wont need to store it for the child nodes
    Would the actual file names (mFormatVB) be classed as GrandChildNodes?

    Don't know why it started at 22. When I redid the tables I deleted the old DB and created a new one.
    Last edited by aikidokid; Apr 3rd, 2007 at 10:55 AM.
    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

  21. #21

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    This is now my tbl_Nodes layout:

    Node_ID..NodeName...........ChildNodeName
    22..........API
    23..........Databases........... Access
    24..........Databases............Excel
    25..........SQL
    26..........VB Code.............Collections
    27..........VB Code..............Forms
    28..........VB Code..............Functions
    29..........VB Code..............Modules
    30..........VB Code..............Subs
    31..........VB Code..............UDT
    32..........VBA....................Access
    33..........VBA....................Excel

    When I get to the line of code to add:
    24 - Databases - Excel
    I am getting the error:
    Element not found.

    On this line of code:
    vb Code:
    1. .Nodes.Add "N" & rs.Fields("Node_ID").Value, tvwChild, strNodeChild, "Folder Closed"
    "N" & rs.Fields("Node_ID").Value = 24
    strNodeChild = Excel

    I can't work this out as it loops through as (I) would expect it to, and shows the values I would expect.

    I have the string array NodesKey(keyctr) that holds the Nodes key number and field value. I have added a string called OldStrNodeParent to use to loop through and load the Child Nodes.

    This is what I have so far;
    vb Code:
    1. With tvwCode
    2.     .Nodes.Add , , "Source", "Source Code", "Folder Closed"
    3.     Do While Not rs.EOF
    4.         'check if node is same or different
    5.         If strNodeParent <> rs.Fields("NodeName").Value Then
    6.             'if different, it's a new parent node
    7.             strNodeParent = rs.Fields("NodeName").Value
    8.             OldStrNodeParent = rs.Fields("NodeName").Value
    9.             'add the new node, with the new key and it's name
    10.             .Nodes.Add "Source", tvwChild, "N" & rs.Fields("Node_ID").Value, strNodeParent, "Folder Closed"
    11.             If PCtr = 0 Then
    12.                 strParent(PCtr) = strNodeParent
    13.                 NodesKey(KeyCtr) = strNodeParent & "=N" & rs.Fields("Node_ID").Value
    14.             Debug.Print NodesKey(KeyCtr)
    15.                 PCtr = PCtr + 1
    16.                 KeyCtr = KeyCtr + 1
    17.             Else
    18.                 ReDim Preserve strParent(UBound(strParent) + 1)
    19.                 strParent(PCtr) = strNodeParent
    20.                 ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    21.                 NodesKey(KeyCtr) = strNodeParent & "=N" & rs.Fields("Node_ID").Value
    22.             Debug.Print NodesKey(KeyCtr)
    23.                 PCtr = PCtr + 1
    24.                 KeyCtr = KeyCtr + 1
    25.             End If
    26.         End If
    27.             If strNodeParent = OldStrNodeParent Then
    28.                 'if needed, add the child
    29.                 'check if there are any child nodes -
    30.                 'if Fields is "" then no new child nodes
    31.                 'move on to next parent node
    32.                 If strNodeChild <> rs.Fields("ChildNodeName").Value & "" Then
    33.                     'if Fields is not empty - add new child node
    34.                     strNodeChild = rs.Fields("ChildNodeName").Value & ""
    35.                         If strNodeChild <> "" Then  '(dont add Null/blank child nodes)
    36.                             'add the new child node with the path of the parent node
    37.                             .Nodes.Add "N" & rs.Fields("Node_ID").Value, tvwChild, strNodeChild, "Folder Closed"
    38.                             If CCtr = 0 Then
    39.                                 strChild(CCtr) = strNodeParent & " " & strNodeChild
    40.                                 If KeyCtr > 0 Then
    41.                                     ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    42.                                     NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & "=N" & rs.Fields("Node_ID").Value
    43.                                 Debug.Print NodesKey(KeyCtr)
    44.                                     KeyCtr = KeyCtr + 1
    45.                                 Else
    46.                                     NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & "=N" & rs.Fields("AutoNumber").Value
    47.                                 Debug.Print NodesKey(KeyCtr)
    48.                                     KeyCtr = KeyCtr + 1
    49.                                 End If
    50.                                 CCtr = CCtr + 1
    51.                             Else
    52.                                 ReDim Preserve strChild(UBound(strChild) + 1)
    53.                                 strChild(CCtr) = strNodeParent & " " & strNodeChild
    54.                                 ReDim Preserve NodesKey(UBound(NodesKey) + 1)
    55.                                 NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & "=N" & rs.Fields("AutoNumber").Value
    56.                                 CCtr = CCtr + 1
    57.                                 KeyCtr = KeyCtr + 1
    58.                             End If
    59.                         End If
    60.                 End If
    61.             End If
    62.        
    63.         rs.MoveNext
    64.     Loop
    65. End With
    66. 'close the recordset
    67. rs.Close
    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

  22. #22
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Quote Originally Posted by aikidokid
    So what I have done here is to save into the new variable the following:
    API=N22
    VB Code=N23
    etc

    Is this what you meant?
    Nope.. what I meant was just store the last value to a single variable (so as soon as "VB Code" loads it would contain "N23").

    This is so you can use it as the first parameter to .Add, which specifies the parent node (as you are getting the first parameter from the recordset, your current code basically specifies itself - before it is added!).

    Would the actual file names (mFormatVB) be classed as GrandChildNodes?
    Basically yes in most cases (in some they are just Child nodes), but technically they are Leaf nodes - they have a parent (and possibly grandparent etc), but no children of their own.

    Don't know why it started at 22. When I redid the tables I deleted the old DB and created a new one.
    That sounds a bit odd, but isn't something to worry about - as long as the other table uses the same numbers it will work fine.

    I have the string array NodesKey(keyctr) that holds the Nodes key number and field value. I have added a string called OldStrNodeParent to use to loop through and load the Child Nodes.
    You don't actually need these, or any of the other arrays.

    By ordering the data in the recordset (I think we added an Order By?) you can be sure that all items with the same NodeName will be grouped together - and as strNodeParent etc are only set within the If statement, they will always contain the appropriate parent.

    You just need strNodeParent (so that you can tell when a new parent should be added) and a string variable (perhaps strNodeParentID ?) to contain "Nxx", which allows the child nodes to be added to it.

  23. #23

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Quote Originally Posted by si_the_geek
    Basically yes in most cases (in some they are just Child nodes), but technically they are Leaf nodes - they have a parent (and possibly grandparent etc), but no children of their own.
    So will I be adding nodes for these when I get to loading them?

    Quote Originally Posted by si_the_geek
    That sounds a bit odd, but isn't something to worry about - as long as the other table uses the same numbers it will work fine.
    I have re-done the DB again, and it is starting from 1. The original DB ended at 21, so for some reason it carried on from there.

    Quote Originally Posted by si_the_geek
    You don't actually need these, or any of the other arrays.
    So you wouldn't store the nodes names, Parent & Child, in the array to populate other combo boxes in the app, you would just make a call to the DB each time they were needed?

    So far I have the following code, which adds all of the Parent Nodes, but is having a problem loading the Child nodes.
    The error is on the line where the node is added in the second If statement.
    I know what is causing the error, I just don't know how to change it to to get it to work.
    It's the KEY parameter of the .Node.Add line.
    I am not sure what this is or where I am getting it from.
    vb Code:
    1. With tvwCode
    2.     .Nodes.Add , , "Source", "Source Code", "Folder Closed"
    3.     Do While Not rs.EOF
    4.         'check if node is same or different
    5.         If strNodeParent <> rs.Fields("NodeName").Value Then
    6.             'if different, it's a new parent node
    7.             strNodeParent = rs.Fields("NodeName").Value
    8.             'add the new node, with the new key and it's name
    9.             .Nodes.Add "Source", tvwChild, "N" & rs.Fields("Node_ID").Value, strNodeParent, "Folder Closed"
    10.             strNodeParentID(KeyCtr) = "N" & rs.Fields("Node_ID").Value
    11.             Debug.Print strNodeParentID(KeyCtr)
    12.         End If
    13.  
    14.         If strNodeChild <> rs.Fields("ChildNodeName").Value Then
    15.             Do While Not rs.EOF
    16.                 strNodeChild = rs.Fields("ChildNodeName").Value
    17.                 .Nodes.Add strNodeParentID(KeyCtr), tvwChild, strNodeChild, "Folder Closed"
    18.                 strNodeParentID(KeyCtr) = "N" & rs.Fields("Node_ID").Value
    19.                 Debug.Print strNodeParentID(KeyCtr)
    20.             Loop
    21.         End If
    22.            
    23.         KeyCtr = KeyCtr + 1
    24.         ReDim Preserve strNodeParentID(UBound(strNodeParentID) + 1)
    25.                
    26.         rs.MoveNext
    27.     Loop
    28. End With
    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

  24. #24
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,328

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Quote Originally Posted by aikidokid
    So will I be adding nodes for these when I get to loading them?
    Yep.


    So you wouldn't store the nodes names, Parent & Child, in the array to populate other combo boxes in the app, you would just make a call to the DB each time they were needed?
    Correct.. as the chances are you don't want exactly the same data - and the database is far better at finding/sorting data than VB code can ever be (actually for an Access database on the local computer that isn't completely true, but it will be less work!).

    So far I have the following code, which adds all of the Parent Nodes, but is having a problem loading the Child nodes.
    The error is on the line where the node is added in the second If statement.
    I know what is causing the error, I just don't know how to change it to to get it to work.
    It's the KEY parameter of the .Node.Add line.
    I am not sure what this is or where I am getting it from.
    You don't need it - strNodeParentID should just be a string (containing the latest parent), not an array of strings.

    This also removes the need for KeyCtr, and ReDim Preserve (which is so slow it would lose a race to a dead snail!).

    By the way, that inner Do Loop shouldn't be there.

  25. #25

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

    Re: [RESOLVED] Loading GrandChildNodes from DB

    Quote Originally Posted by si_the_geek
    You don't need it
    That explains why I couldn't find it
    Quote Originally Posted by si_the_geek
    By the way, that inner Do Loop shouldn't be there.
    I had already removed that. It was just one of my attempts to get it to work before I posted - again.

    Just in case somebody does a search, this is what I have and it works as expected.
    BTW. It's a lot less code than I had before.

    vb Code:
    1. With tvwCode
    2.     .Nodes.Add , , "Source", "Source Code", "Folder Closed"
    3.     Do While Not rs.EOF
    4.         'check if node is same or different
    5.         If strNodeParent <> rs.Fields("NodeName").Value Then
    6.             'if different, it's a new parent node
    7.             strNodeParent = rs.Fields("NodeName").Value
    8.             'add the new node, with the new key and it's name
    9.             .Nodes.Add "Source", tvwChild, "N" & rs.Fields("Node_ID").Value, strNodeParent, "Folder Closed"
    10.             strNodeParentID = "N" & rs.Fields("Node_ID").Value
    11.         End If
    12.  
    13.         If strNodeChild <> rs.Fields("ChildNodeName").Value Then
    14.             strNodeChild = rs.Fields("ChildNodeName").Value
    15.             .Nodes.Add strNodeParentID, tvwChild, , strNodeChild, "Folder Closed"
    16.         End If
    17.        
    18.         rs.MoveNext
    19.     Loop
    20. End With
    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
  •  



Featured


Click Here to Expand Forum to Full Width