Visual Basic 11Visual Basic 12Windows 2008 R2Windows 2008Windows VistaWindows 7Windows 2003WindowsVisual Basic
An Workaround for Double Click on Treeview Checkbox





5.00/5 (1 vote)
This tip is used to fix a workaround for a bug in double click on checkbox
Introduction
This tip is used for a workaround for this link:
Background
When I try to migrate a VB6 treeview
project to VB.NET, I faced one of the above mentioned issues and also problem for double click to expand and collapse too. To fix these issues, I wrote the following code.
Using the Code
The code is already posted by SwissMatt. I am just implementing some more things to enable the doubleclick
event in the Treeview
while clicking on the checkbox
.
Public Class MyTreeView
Inherits TreeView
Protected Overrides Sub WndProc(ByRef m As Message)
' Suppress WM_LBUTTONDBLCLK
If (m.Msg = &H203) Then
Dim Hitpoint As Point = New Point(CInt(m.LParam))
Dim tvhti As TreeViewHitTestInfo = HitTest(Hitpoint)
If tvhti IsNot Nothing AndAlso tvhti.Location = TreeViewHitTestLocations.StateImage Then
Me.SelectedNode = tvhti.Node
Dim tvs As New TreeNodeMouseClickEventArgs_
(Me.SelectedNode, Windows.Forms.MouseButtons.Left, 2, Hitpoint.X, Hitpoint.Y)
Dim mvs As New MouseEventArgs(Windows.Forms.MouseButtons.Left, 2, Hitpoint.X, Hitpoint.Y, 0)
OnNodeMouseDoubleClick(tvs)
OnMouseDoubleClick(mvs)
OnDoubleClick(New EventArgs)
If tvhti.Node.IsExpanded Then
SendKeys.Send("{LEFT}")
Else
SendKeys.Send("{RIGHT}")
End If
m.Result = IntPtr.Zero
Return
Else
MyBase.WndProc(m)
End If
Else
MyBase.WndProc(m)
End If
End Sub
End Class
Points of Interest
Implementing double click on the Treeview Checkbox
is much harder. Moreover, the expand and collapse behaviour is my idea.