Treeview - relative position

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

forgive me, but I'm fairly new to VB.Net - having only used VB6 in the
past - -
I can easily place a node on the treeview (tv1.nodes.add(key, text)
BUT -
in VB6, we'd add a child node (TV1.NOdes.add...), and in that string, we'd
pick the parent/relative node, so that it would be placed under the correct
node....

How is that accomplished now?
 
Elmo said:
I can easily place a node on the treeview (tv1.nodes.add(key, text)
BUT -
in VB6, we'd add a child node (TV1.NOdes.add...), and in that string, we'd
pick the parent/relative node, so that it would be placed under the correct
node....

How is that accomplished now?

In much the same way.

Every TreeNode has a Nodes collection to which you can add [child]
TreeNodes. Annoyingly, in VB'2003, anyway, the Add method seems to
return an Index, not a TreeNode proper, so you have to muck about a
/bit/, as in

Dim oRootNode as TreeNode _
= tv1.Nodes.Add( "Root" )
Dim iIndex as Integer _
= oRootNode.Nodes.Add( "Child 1" )
Dim oChild1 as TreeNode _
= tv1.Nodes( iIndex )

iIndex = oChild1.Nodes.Add( "Grandchild 1" )
Dim oGrandChild As TreeNode _
= oChild1.Nodes( iIndex )

All of which is fine when initially loading the tree, but finding an
item that you've already loaded is a pain, since the TreeView doesn't
have keyed Nodes any more. But it's easy enough to implement your own.

HTH,
Phill W.
 
Back
Top