CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005
    JHB South Africa

    [RESOLVED] Checkbox enabled Treeview Bug - workaround !!

    So i'm using a treeview with checkbox's enabled, and via some customization I'm only enabling the checkbox's on the root nodes (see attached pic), which was actually not too difficult, and not the issue here..

    There is a serious bug in the Checkbox Double Click.. Dbl Clicking on the Checkbox itself and not the node text, presents some interesting issues. I've done many hours of coding and recoding and trapping, and this is what i have worked out so far..

    The double Clicking on the Checkbox acts very much like a Dbl click hold... Ie. Click, Release, Click, Hold.. A third Click on the checkbox does the final release of the Dbl click... NOW.. this bug has been reported to MS earlier this year ... (MS connect thread here) and MS has simply shrugged it off with a
    Thank you for reporting this issue. -- We have evaluated the issue that you have reported and at this point in the product's lifecycle, it does not meet the criteria to be addressed.
    IE... we just not interested in fixing this BUG, and go find a workaround...

    After some searching.. i found this thread with a workaround.. Ohhhhh shucks it's in C again...

    So here's the VB.NET equivalent....
    Imports System
    Imports System.Windows.Forms
    Public Class MyTreeView
        Inherits TreeView
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = &H203 Then
                Dim LocalPos = PointToClient(Cursor.Position)
                Dim hitTestInfo = HitTest(LocalPos)
                If (hitTestInfo.Location = TreeViewHitTestLocations.StateImage) Then
                    m.Result = 0
                End If
            End If
        End Sub
    End Class
    Now what i did was add a new project to the solution called 'MyTreeView', with just the single class (you may need to add the System.Windows.Forms .NET reference to the project.)
    Compiled the project, then added the 'MyTreeView' project as a reference to the project where i needed the treeview, then simply used Mytreeview.mytreeview instead of system.windows.forms.treeview object..
        Friend WithEvents TVModules As MyTreeView.MyTreeView
            Me.TVModules = New MyTreeView.MyTreeView
            Me.TVModules.CheckBoxes = True
            Me.TVModules.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll
            Me.TVModules.Location = New System.Drawing.Point(81, 32)
            Me.TVModules.Name = "TVModules"
            Me.TVModules.ShowNodeToolTips = True
            Me.TVModules.Size = New System.Drawing.Size(575, 199)
            Me.TVModules.TabIndex = 54
    This effectively completely disables Dbl clicking on the treeview checkbox, but dbl clicking on the node will expand and collapse the nodes..

    I hope someone else gets some joy, and relief with this...
    Attached Images Attached Images  
    Last edited by GremlinSA; June 26th, 2013 at 09:26 AM.
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  2. #2
    Join Date
    Jul 2001
    Sunny South Africa

    Re: [RESOLVED] Checkbox enabled Treeview Bug - workaround !!

    Nice post! Thanks for sharing the workaround

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.