PDA

View Full Version : [SOLVED] TreeView



Kaizer
12-30-2004, 01:25 AM
Hi there,

I am trying to get the value (or text) of the Node when I double click on the treeView. So far no luck. Can you help to write a code in VBA?

I tried this but it does not work:


Private Sub treeView1_DblClick()
MsgBox Node.Text
End Sub

Jacob Hilderbrand
12-30-2004, 01:58 AM
Try the NodeClick event instead.


Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Me.Caption = Node.Text
End Sub

Kaizer
12-30-2004, 02:15 AM
Jacob,

I tryed this but this is what I get:

Copile Error:
Procedure declaration does not match description of event or procedure have the same name.

Jacob Hilderbrand
12-30-2004, 02:21 AM
Can you post an attachment with your workbook?

Check your code to make sure that there are no subs with the same name.

Jacob Hilderbrand
12-30-2004, 02:22 AM
Also to be sure that the code is correct for your version on Excel. Select TreeView1 from the left drop down on the Code Window in the VBE. And select NodeClick from the right drop down. The correct names for the sub and the arguments will be written in for you.

Jacob Hilderbrand
12-30-2004, 02:32 AM
You can download a TreeView Control example here (http://www.vbaexpress.com/forum/showthread.php?t=1509).

Kaizer
12-30-2004, 02:39 AM
Strange, but that is exactly what I was doing. Still does not work. There is no other procedures with the same name.
Is there a way to attach a workbook with the code?

Kaizer
12-30-2004, 02:45 AM
But your example works for one click. I need it working on double click.

Jacob Hilderbrand
12-30-2004, 02:53 AM
Strange, but that is exactly what I was doing. Still does not work. There is no other procedures with the same name.
Is there a way to attach a workbook with the code?Click on "Post Reply" and scroll down to where it says "Manage Attachments". You need to zip the workbook first then you can upload it.

Jacob Hilderbrand
12-30-2004, 02:57 AM
But your example works for one click. I need it working on double click.
Ok, I think I understand what you want to do now. Try this:



Option Explicit
Dim NodeValue As String

Private Sub TreeView1_DblClick()
Me.Caption = NodeValue
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
NodeValue = Node.Text
End Sub

Kaizer
12-30-2004, 03:08 AM
Jacob,

Thank you. It works. I guess there is no need to attach the file.

Jacob Hilderbrand
12-30-2004, 03:18 AM
You're Welcome

Take Care