Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 88
DIR issue 7 51
I need help formating a date variable in my VB.Net application 2 44
How to Add / Edit Windows Menu 4 51
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now