Solved

TreeView Control

Posted on 2004-04-04
7
282 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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