Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Treeview + CheckBox + ContextMenu
Message
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Treeview + CheckBox + ContextMenu
Miscellaneous
Thread ID:
00877414
Message ID:
00877414
Views:
64
VB.Net 2003 - Windows application

I have a treeview in my application that has checkboxes to all items.

I have added a ContextMenu to the treeview that has 2 items :
-Select all children
-Unselect all children

Up to here I have no problems. Children get selected/unselected correctly.

My problem is that the context menu is displayed even if click the left-mouse button on the checkbox and not on the node caption.

Steps to reproduce the problem:
1. Right-click a node
2. Select a menu item
3. Clcik on a node checkbox with the left mouse button. The context menu is shown and it is not supposed!
4. Click on a node caption.
5. Clcik on a node checkbox with the left mouse button. The context menu is NOT shown as supposed!

How to fix that?

This is a portion of the code I use to display the context menu:
    Private Sub mnuTVUnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTVUnselect.Click
        tvwSecurite.BeginUpdate()
        Me.TreeviewChildrenCheck(tvwSecurite.SelectedNode, False)
        tvwSecurite.EndUpdate()
    End Sub

    Private Sub mnuTVSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTVSelect.Click
        tvwSecurite.BeginUpdate()
        Me.TreeviewChildrenCheck(tvwSecurite.SelectedNode, True)
        tvwSecurite.EndUpdate()
    End Sub

    Private Sub tvwSecurite_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwSecurite.MouseUp
        ' Show menu only if Right Mouse button is clicked
        If e.Button = MouseButtons.Right AndAlso Me.mclsProfil.IsEditing Then

            tvwSecurite.SelectedNode = tvwSecurite.GetNodeAt(e.X, e.Y)

            If tvwSecurite.SelectedNode Is Nothing Then Exit Sub

            ' Point where mouse is clicked
            Dim p As Point = New Point(e.X, e.Y)
            ' Show the appropriate ContextMenu 
            mnuTreeview.Show(tvwSecurite, p)
        End If
    End Sub 
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Next
Reply
Map
View

Click here to load this message in the networking platform