Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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?
0
glit
Asked:
glit
  • 2
2 Solutions
 
Tapan PattanaikSenior EngineerCommented:
hi glit,

         just have a look.

TreeView Control for Visual Basic 6.0 Users:

http://msdn.microsoft.com/en-us/library/ms172635%28VS.80%29.aspx

TreeView Control:

http://www.developerfusion.com/article/77/treeview-control/

TreeView Control:

http://oreilly.com/catalog/vbcnut/chapter/ch05-tv.html



0
 
danaseamanCommented:
Simple example for 5 subnodes:

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

Open in new window

0
 
danaseamanCommented:
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
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now