Avatar of Jmjl3
Jmjl3

asked on 

TreeView Control

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.
Visual Basic Classic

Avatar of undefined
Last Comment
Jmjl3
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bobeo
Bobeo

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
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jmjl3
Jmjl3

ASKER

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
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo