Link to home
Start Free TrialLog in
Avatar of glit
glit

asked on

Visual Basic Tree View Control - How many branches/nodes can I have???

I have a very basic understanding on how the TreeView control works.  I was wondering if it is possible for a Node of a Node to have a Node? ... and so on.   It seems as if it stops at 2 nodes.  Is this a limitation or is it possible?  If so, how?
ASKER CERTIFIED SOLUTION
Avatar of Tapan Pattanaik
Tapan Pattanaik
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Dana Seaman
Dana Seaman
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Better example showing usage of Keys and Node objects.

Option Explicit
 
Private Sub Form_Load()
   Dim nod              As Node
   Dim i                As Long
   Dim j                As Long
 
   TreeView1.Nodes.Add , , "Root", "Root"
 
   For i = 1 To 5
      Set nod = TreeView1.Nodes.Add("Root", tvwChild, "Item" & i, "Item" & i)
      For j = 1 To 10
         Set nod = TreeView1.Nodes.Add(nod, tvwChild, , "SubNode" & j)
         nod.Expanded = True
      Next
   Next
   TreeView1.Nodes("Item1").Expanded = True
   TreeView1.Nodes("Root").Expanded = True
 
End Sub

Open in new window

TreeviewSubNodes.png