Need help with Treeview control ??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there I am extreamly frustrated because I have recently discoverd the
treeview control but am unable to use it. I have found nothing in the Excel
VBA help files of use and every search I have done for a example code has
been either far to complex or had errors in in it before I edited anything.
Could someone please help me with a small very very very basic example code
for populating and using the Treeview control on a vba form.

Thanks, Dan
 
Well that may be true however I have added The treeview control to my forms
toolbox and have such added the control to my form I am able to refference it
withing Excel VBA code too for example

With Me
Treview1.Nodes.Add(blah blah blah)
end with
but when I add the nodes and run the control on my form nothing happens
I know that this control can be used in a Excel VBA form.
Im just not sure how to get it going has anyone used this control on a Excel
VBA form before that can help me with a small working sample ?

Thanks Dan Thompson
 
Hi Dan

Short explanation of the Blah blah part:

Nodes.Add(Key of parent node, relation to parent node, unique node key, node
text, optional icon to display)

Private Sub UserForm_Initialize()
Dim L1 As Long, L2 As Long
With Me.TreeView1
Dim NodX As Node
Set NodX = .Nodes.Add(, , "Root", "My main node")
Set NodX = Nothing
For L1 = 1 To 6
Set NodX = .Nodes.Add("Root", tvwChild, _
"Sub" & L1, "Child " & L1)
NodX.EnsureVisible
Set NodX = Nothing
For L2 = 1 To 12
Set NodX = .Nodes.Add("Sub" & L1, tvwChild, _
"Sub" & L1 & "sub" & L2, "Grandhild " & L1)
Set NodX = Nothing
Next
Next
End With
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
If Node.Key = "Root" Then
MsgBox "I'm root."
Else
MsgBox "You just clicked " & Node.Key & ", proud child of the great " &
_
Node.Parent.Key
End If
End Sub

HTH. Best wishes Harald
 
Thanks Harald
That worked GREAT!
You were a big help, realy apreciate your input.

Dan
 
Dan Thompson said:
Thanks Harald
That worked GREAT!
You were a big help, realy apreciate your input.

Glad to hear that Dan. Thanks for the feedback.
Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top