Click here to Skip to main content
15,885,683 members
Articles / Programming Languages / Visual Basic 12
Tip/Trick

An Workaround for Double Click on Treeview Checkbox

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
10 Jun 2014CPOL 11.8K   4  
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.

VB.NET
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --