Link to home
Start Free TrialLog in
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.
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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