I'm not sure what your "Start" routine is doing here - do you want all of
your top level nodes to start off with the value "1"? If you want Unique
IDs then this is wrong, however, I'm guessing you want to label nodes by
their depth, in which case, its correct. When you say "pos is the position
in the collection of Ids" I get confused. What is the collection of Ids?
If pos is supposed to be a unique position, then Pos should be incremented
within the loops, not outside of them.
More information required I guess ;)
"Jan Krouwer" <ja*********@comcast.net> wrote in message
news:nzOkb.825705$YN5.855111@sccrnsc01...
I have a treeview which is populated from a relational database. In order
to copy part of the tree, I need to add to the database the relationship of
the part of the tree to be copied but with new ids. I have built a collection
of the right number of ids. I am using the following code to recursively go
through the tree (some code left out). Pos is the position in the
collection of ids - I need to select the correct ids (need to use previous ids) to
maintain the node relationship which is done by testing node properties.
What is strange is that pos is the correct number in this routine but when
the last node is reached, pos changes to the wrong number. Any ideas or
another way to add a hierarchical relationship to a database from a set of
treeview nodes.
Private Sub Copy(ByVal n As TreeNode, ByVal pos As Integer)
Dim aNode As TreeNode
pos=pos+1
For Each aNode In n.Nodes
Copy(aNode, pos)
Next
End Sub
' Call the procedure using the top nodes of the treeview.
Private Sub CopyStart(ByVal aTreeView As TreeView)
Dim n As TreeNode
For Each n In aTreeView.Nodes
Copy(n,1)
Next
End Sub