Solved

TreeView Control

Posted on 2004-04-04
7
277 Views
Last Modified: 2010-05-02
I need help with the TreeView control! I need to know how to add Root items and child and parent items etc, and if an item is selected to display something in a label or whatever. I've looked at the MSDN article on the TreeView control, but that didn't help at all.
0
Comment
Question by:Jmjl3
7 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 25 total points
ID: 10752459
0
 
LVL 3

Expert Comment

by:Bobeo
ID: 10752526
Glad to see that i'm not the only one who thinks MSDN isn't overly helpful!

Give this a try as a starter?

Dim XNode As Node

Private Sub Form_Load()
'set up treeview properties
TreeView1.Style = tvwTreelinesPlusMinusPictureText
TreeView1.LineStyle = tvwRootLines

'add root nodes
Set XNode = TreeView1.Nodes.Add(, , "Root1", "Root1")
Set XNode = TreeView1.Nodes.Add(, , "Root2", "Root2")
Set XNode = TreeView1.Nodes.Add(, , "Root3", "Root3")

'add child nodes
Set XNode = TreeView1.Nodes.Add("Root1", tvwChild, "Root1Child1", "Child1")
Set XNode = TreeView1.Nodes.Add("Root1", tvwChild, "Root1Child2", "Child2")
Set XNode = TreeView1.Nodes.Add("Root1", tvwChild, "Root1Child3", "Child3")

Set XNode = TreeView1.Nodes.Add("Root2", tvwChild, "Root2Child1", "Child1")
Set XNode = TreeView1.Nodes.Add("Root2", tvwChild, "Root2Child2", "Child2")
Set XNode = TreeView1.Nodes.Add("Root2", tvwChild, "Root2Child3", "Child3")

Set XNode = TreeView1.Nodes.Add("Root3", tvwChild, "Root3Child1", "Child1")
Set XNode = TreeView1.Nodes.Add("Root3", tvwChild, "Root3Child2", "Child2")
Set XNode = TreeView1.Nodes.Add("Root3", tvwChild, "Root3Child3", "Child3")

End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Label1 = Node
End Sub


Hope it helps

Bobeo
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 25 total points
ID: 10752684
Also, take a look at the TreeView solution I posted here: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20921800.html

Read the poster's requirements closely before looking at the code.

Idle_Mind
0
 

Author Comment

by:Jmjl3
ID: 10791590
I have a problem with the code Bobeo gave me.

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Label1 = Node
End Sub

That doesen't work. I get an error saying:

"Compile Error:
User-defined type not defined"

And it highlights
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node
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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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

20 Experts available now in Live!

Get 1:1 Help Now