treeview node expansion: how to stop doubleclick raise AfterExpand

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

Guest

hi

i would like to handle the expansion of a tree node differently based on what the user did. for some nodes, although they have children, double-click should _not_ open the node but instead do something else (e.g.: open a window). for these nodes, the user should only be able to open the node by using the (+) sign. for other nodes (+) and dblclick shoule be the same

this is essentially the same behaviour that visual studio has for nodes with .resx files as children: a double click will not open the node; to open it and see the resx, you need to use (+)

now, i'm aware of BeforeExpand() and i know how to cancel the expand event here. however, there is no information as to how the expansion was invoked. thus, it seems, its not possible to handle this situation with the treeview. or is there

any pointers how to archive what i'd like to archive

WM_TH
thomas woelfer
 
Here's one approach:
http://groups.google.se/groups?ie=UTF-8&oe=UTF-8&as_umsgid=u0dNwrBBBHA.1340@tkmsftngp07&lr=&hl=sv

/claes

thomas woelfer said:
hi.

i would like to handle the expansion of a tree node differently based on
what the user did. for some nodes, although they have children, double-click
should _not_ open the node but instead do something else (e.g.: open a
window). for these nodes, the user should only be able to open the node by
using the (+) sign. for other nodes (+) and dblclick shoule be the same.
this is essentially the same behaviour that visual studio has for nodes
with .resx files as children: a double click will not open the node; to open
it and see the resx, you need to use (+).
now, i'm aware of BeforeExpand() and i know how to cancel the expand event
here. however, there is no information as to how the expansion was invoked.
thus, it seems, its not possible to handle this situation with the treeview.
or is there?
 
well, sorry, disregard my previous answer... - because unfortunately, thi
doesn't work

the BeforeExpand handler is called _before_ the DoubleClick handler. thus, it doesn't hel
to set that flag

any other ideas

WM_TH
thomas woelfer
 
OK, try this instead:

Public Class TreeViewEx
Inherits TreeView

Private bDoubleClick As Boolean = False

Protected Overrides Sub OnBeforeExpand(ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs)
If bDoubleClick Then
e.Cancel = True
bDoubleClick = False
Else
MyBase.OnBeforeExpand(e)
End If
End Sub

Private Const WM_LBUTTONDBLCLK As Integer = &H203

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_LBUTTONDBLCLK Then
bDoubleClick = True
End If
MyBase.WndProc(m)
End Sub
End Class

/claes
 
Back
Top