Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2009-07-02
Medium Priority
Last Modified: 2013-12-26
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?
Question by:glit
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 21

Accepted Solution

Tapan Pattanaik earned 750 total points
ID: 24770018
hi glit,

         just have a look.

TreeView Control for Visual Basic 6.0 Users:


TreeView Control:


TreeView Control:


LVL 22

Assisted Solution

danaseaman earned 750 total points
ID: 24776873
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
  root.Expanded = True
End Sub

Open in new window

LVL 22

Expert Comment

ID: 24778015
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
   TreeView1.Nodes("Item1").Expanded = True
   TreeView1.Nodes("Root").Expanded = True
End Sub

Open in new window


Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question