Click here to Skip to main content
Click here to Skip to main content

An Workaround for Double Click on Treeview Checkbox

, 10 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to 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.

License

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

Share

About the Author

Thava Rajan
Software Developer (Senior)
India India
No Biography provided
Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 10 Jun 2014
Article Copyright 2014 by Thava Rajan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid