'==============================================================================================
'Load treeview nodes from DB
'Load arrays holding the names of the 'Parents' and the 'Children' nodes
'Also load 'NodesKey' array to use later to open the TV with the option saved in the Registry
'==============================================================================================
With tvwCode
Do While Not rs.EOF
'check if node is same or different
If strNodeParent <> rs.Fields("tvwNodes").Value Then
'if different, it's a new parent node
strNodeParent = rs.Fields("tvwNodes").Value
'add 1 to the key
lngNodeParent = lngNodeParent + 1
'update key number if previous Parent node had children
If lngNodeParent <= lngNodeChild Then lngNodeParent = lngNodeChild + 1
'add the new node, with the new key and it's name
.Nodes.Add , , "P" & CStr(lngNodeParent), strNodeParent, "Folder Closed"
If PCtr = 0 Then
strParent(PCtr) = strNodeParent
NodesKey(KeyCtr) = strNodeParent & " P" & CStr(lngNodeParent)
PCtr = PCtr + 1
KeyCtr = KeyCtr + 1
Else
ReDim Preserve strParent(UBound(strParent) + 1)
strParent(PCtr) = strNodeParent
ReDim Preserve NodesKey(UBound(NodesKey) + 1)
NodesKey(KeyCtr) = strNodeParent & " P" & CStr(lngNodeParent)
PCtr = PCtr + 1
KeyCtr = KeyCtr + 1
End If
End If
'if needed, add the child
'check if there are any child nodes -
'if Fields is "" then no new child nodes
'move on to next parent node
If strNodeChild <> rs.Fields("tvwChildNodes").Value & "" Then
'if Fields is not empty - add new child node
strNodeChild = rs.Fields("tvwChildNodes").Value & ""
If strNodeChild <> "" Then '(dont add Null/blank child nodes)
'add 1 to the key
lngNodeChild = lngNodeChild + 1
'if necessary add 1 to make number unique
If lngNodeChild <= lngNodeParent Then lngNodeChild = lngNodeParent + 1
'add the new child node with the path of the parent node
.Nodes.Add "P" & CStr(lngNodeParent), tvwChild, "C" & CStr(lngNodeChild), strNodeChild, "Folder Closed"
If CCtr = 0 Then
strChild(CCtr) = strNodeParent & " " & strNodeChild
If KeyCtr > 0 Then
ReDim Preserve NodesKey(UBound(NodesKey) + 1)
NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
KeyCtr = KeyCtr + 1
Else
NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
KeyCtr = KeyCtr + 1
End If
CCtr = CCtr + 1
Else
ReDim Preserve strChild(UBound(strChild) + 1)
strChild(CCtr) = strNodeParent & " " & strNodeChild
ReDim Preserve NodesKey(UBound(NodesKey) + 1)
NodesKey(KeyCtr) = strNodeParent & " " & strNodeChild & " " & "C" & CStr(lngNodeChild)
CCtr = CCtr + 1
KeyCtr = KeyCtr + 1
End If
End If
End If