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

Posted on 2009-07-02
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 250 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 250 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

617 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