Solved

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

Posted on 2009-07-02
3
237 Views
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?
0
Comment
Question by:glit
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Tapan Pattanaik earned 250 total points
ID: 24770018
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
 
LVL 22

Assisted Solution

by:danaseaman
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
  Next
  root.Expanded = True
End Sub

Open in new window

0
 
LVL 22

Expert Comment

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

Open in new window

TreeviewSubNodes.png
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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