Multi-level TreeNode storing?

  • Thread starter Thread starter Brian Tkatch
  • Start date Start date
B

Brian Tkatch

I have a form that has six possible setups for a TreeView, though after
the Tree is shown, they all act the same way. The Nodes have three or
four levels.

Repopulating the tree for another setup takes a moment due to the logic
involved in populating it. I am wondering it it would be faster if i
could "save" the nodes for later.

CopyTo and AddRange seem to support one level. Is there soimething
similar for a multi-dimensional array?

B.
 
Brian said:
Repopulating the tree for another setup takes a moment due to the logic
involved in populating it. I am wondering it it would be faster if i
could "save" the nodes for later.

If your "setups" (like mine) involve different "arrangements" of the
same Nodes, then yes.
Grab a reference, outside the TreeView, to each "group" node that you
want to save, clear out the TreeView and rebuild the new structure, then
add in the Nodes that you're holding, something like

Dim oGroup1 As TreeNode = tv1.Nodes( 1 )
Dim oGroup2 As TreeNode = tv1.Nodes( 2 )
.. . .
tv1.Nodes.Clear()
.. . .
Dim oNode As TreeNode _
= tv1.Nodes.Add( "Part 1" )
oNode.Nodes.Add( oGroup1 )

oNode = tv1.Nods.Add( "Part 2" )
oNode.Nodes.Add( oGroup2 )

HTH,
Phill W.
 
Phill said:
If your "setups" (like mine) involve different "arrangements" of the
same Nodes, then yes.
Grab a reference, outside the TreeView, to each "group" node that you
want to save, clear out the TreeView and rebuild the new structure, then
add in the Nodes that you're holding, something like

Dim oGroup1 As TreeNode = tv1.Nodes( 1 )
Dim oGroup2 As TreeNode = tv1.Nodes( 2 )
. . .
tv1.Nodes.Clear()
. . .
Dim oNode As TreeNode _
= tv1.Nodes.Add( "Part 1" )
oNode.Nodes.Add( oGroup1 )

oNode = tv1.Nods.Add( "Part 2" )
oNode.Nodes.Add( oGroup2 )

HTH,
Phill W.

Thanx for the reply.

Actually, it is the same data, but there are three different ways to
show it, and each has two views based on a flag (thus showing different
data, the two together are everything). Two of the three views add a
newer top level, and do not show anything unless each has all three
levels. The other one has three levels, but shows everything.

So, i do not think your solution will work for me. I need to populate
all six separately.

B.
 
Back
Top