VB TreeView DoubleClick

Hi, I'm using the VB TreeView control. A DoubleClick event does not exist with this control, and am I wondering if there is a way to create or access one.
Thanks,
Mark
[186 byte] By [mgottsch] at [2007-11-15 17:37:43]
# 1 Re: VB TreeView DoubleClick
This can easily be done using the EventVB.dll, downloadable from http://www.MerrionComputing.com/Download/index.htm thus:

'\\ Declarations..
option Explicit

Dim withevents vbLink as EventVB.APIFunctions
Dim withevents vbWndTree as EventVB.ApiWindow

private Sub Form_Load()

set vbLink = new EventVB.APIFunctions

'\\ Subclass the treeview control
set vbWndTree = new EventVB.ApiWindow
vbWndTree.hWnd = me.TreeView1.hWnd
vbLink.SubclassedWindows.Add vbWndTree

End Sub

private Sub Form_Unload(Cancel as Integer)

'\\ Stop subclassing the treeview control
vbLink.SubclassedWindows.Remove vbWndTree
set vbWndTree = nothing
set vbLink = nothing

End Sub

private Sub vbWndTree_WindowMessageFired(byval msg as EventVB.WindowMessages, byval wParam as Long, byval lParam as Long, Cancel as Boolean, ProcRet as Long)

'\\ If double clikc occurs, deal with it..
If msg = WM_LBUTTONDBLCLK then
MsgBox "Left button double clicked on treeview"
End If

End Sub

Hope this helps,
Duncan

---------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
Clearcode at 2007-11-10 0:44:04 >
# 2 Re: VB TreeView DoubleClick
What am I missing? The Treeview I have in my VB 6.0 Professional has a DblClick event.

John G
John G Duffy at 2007-11-10 0:44:58 >
# 3 Re: VB TreeView DoubleClick
John is right. TreeView has DblClick event

Iouri Boutchkine
iouri@hotsheet.com
Iouri at 2007-11-10 0:46:08 >
# 4 Re: VB TreeView DoubleClick
My mistake. What I meant to say is that there is no double-click event associated with a Node in the TreeView. There is NodeClick, but there isn't a NodeDblClick. -> I do not execute the code until the user double clicks on a certain node within the tree.

Thanks,
Mark
mgottsch at 2007-11-10 0:47:05 >
# 5 Re: VB TreeView DoubleClick
If you don't think the following method is too stupid, we can still get the DblClick event through the TreeView control, and refer to the selected node by calling TreeView1.SelectedItem.

private Sub TreeView1_DblClick()
MsgBox TreeView1.SelectedItem.Text
End Sub



Just an idea.

Regards,

Michi
michi at 2007-11-10 0:48:04 >
# 6 Re: VB TreeView DoubleClick
Thanks for the reply. I've thought of this myself, however, if a node is selected and then the user selects anywhere else in the TreeView object (empty space), the node will still be referenced and that code executed. This is almost what I want but not 100% there yet. :)

-Mark
mgottsch at 2007-11-10 0:49:08 >
# 7 Re: VB TreeView DoubleClick
In the DblClick event you need to do a HitTest, to check whether DblClick happened over a node, or empty space

private Sub TreeView1_DblClick(...)
dim oNode as Node
set oNode = TreeView1.HitTest(x, y)
if oNode is nothing then
'Clicked empty space
else
'oNode is the Node that was double
'clicked, do whatever
endif
end sub

hope this helps
gavinrifkind at 2007-11-10 0:50:12 >
# 8 Re: VB TreeView DoubleClick
Thanks for HitTest tip. However, the DblClick event for a TreeView control, doesn't provide x and y values, so i'll need another method to determine what the x and y was. Is there some method to get the current mouse position?

Thanks,
Mark
mgottsch at 2007-11-10 0:51:06 >
# 9 Re: VB TreeView DoubleClick
The MouseDown event fires before the DblClick, so you could save the x and y in Form-Level variables so that they are available at the time of the DblClick.

Alternatively you could use the GetCursorPos API function. This will give you the co-ords of the mousepointer. The problem is they are in Pixels (as all API functions do) and they are relative to the screen, so you have to do some arithmetic to get them relative to your treeview, and in the same scalemode (usually twips)

Hope this helps
gavinrifkind at 2007-11-10 0:52:14 >