Solved

TreeView Control

Posted on 2004-04-04
7
272 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
Comment Utility
0
 
LVL 3

Expert Comment

by:Bobeo
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

10 Experts available now in Live!

Get 1:1 Help Now