Results 1 to 8 of 8

Thread: [2005] Contextual Menu Appearing When i dont want it to

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2006
    Location
    USA
    Posts
    42

    [2005] Contextual Menu Appearing When i dont want it to

    My Contextual menu appears no matter where in the treeview i RMB

    help

    attached image shows my treeview i only want it to appear on "Default" "Roll1" "Roll2" and Roll3"

    Madaxe



    Code:
    Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
            ' Show menu only if Right Mouse button is clicked
            If e.Button = MouseButtons.Right Then
    
                ' Point where mouse is clicked
                Dim p As Point = New Point(e.X, e.Y)
    
                ' Go to the node that the user clicked
                Dim node As TreeNode = TreeView1.GetNodeAt(p)
                TreeView1.SelectedNode = node
    
                If node Is Nothing Then Exit Sub
    
                If node.Text Is "Default" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll1" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll2" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll3" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll4" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll5" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll6" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll7" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll8" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll9" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
                ElseIf node.Text Is "Roll10" Then
                    ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
    
                End If
    
            End If
    
        End Sub
    Attached Images Attached Images  

  2. #2
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [2005] Contextual Menu Appearing When i dont want it to

    dont know the sollution to your problem, but why not use a select case instead of all those ifelse statements?

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2006
    Location
    USA
    Posts
    42

    Re: [2005] Contextual Menu Appearing When i dont want it to

    Can you give me an example

    thks

    Madaxe

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2006
    Location
    USA
    Posts
    42

    Re: [2005] Contextual Menu Appearing When i dont want it to

    ok i figured it out but it still shows the contextual menu i did a watch and stepped through the code it is not showing the menu during the case selection but at the end sub i dont know why its doing that.

    So what ever is selected it shows the contextual menu?

    Madaxe


    Code:
        Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
            ' Show menu only if Right Mouse button is clicked
            If e.Button = MouseButtons.Right Then
    
                ' Point where mouse is clicked
                Dim p As Point = New Point(e.X, e.Y)
    
                ' Go to the node that the user clicked
                Dim node As TreeNode = TreeView1.GetNodeAt(p)
                TreeView1.SelectedNode = node
    
    
                Select Case node.Text
    
                    Case "Catsettings", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"
    
                        Exit Sub
    
                    Case "Default", "Roll1", "Roll2", "Roll3", "Roll4", "Roll5", "Roll6", "Roll7", "Roll8", "Roll9", "Roll10"
    
                        ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
    
                End Select
    
            End If
    
        End Sub

  5. #5
    Addicted Member
    Join Date
    Sep 2007
    Location
    Right behind you
    Posts
    170

    Re: [2005] Contextual Menu Appearing When i dont want it to

    try to replace this

    Code:
                Select Case node.Text
    
                    Case "Catsettings", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"
    
                        Exit Sub
    
                    Case "Default", "Roll1", "Roll2", "Roll3", "Roll4", "Roll5", "Roll6", "Roll7", "Roll8", "Roll9", "Roll10"
    
                        ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
    
                End Select
    For something like this

    Code:
                Select Case node.Text
    
                    Case "Default", "Roll1", "Roll2", "Roll3", "Roll4", "Roll5", "Roll6", "Roll7", "Roll8", "Roll9", "Roll10"
    
                        ContextMenuStrip1.Show(TreeView1, New Point(e.X, e.Y))
    
                    Case Else
    
                        Exit Sub
    
                End Select

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2006
    Location
    USA
    Posts
    42

    Re: [2005] Contextual Menu Appearing When i dont want it to

    Ok it shortened my code great but i still get the contextual menu if i rmb on anything

    im not sure why its still executing the contextual menu


    Madaxe

  7. #7
    Addicted Member
    Join Date
    Sep 2007
    Location
    Right behind you
    Posts
    170

    Re: [2005] Contextual Menu Appearing When i dont want it to

    check your x and y values to see if they change every time you click a diferent place, and also check getnode at, to see if that changes too.

    Then check the grid to see if you didnt bound the context menu to the tree.. .there is a property called contextmenu there.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2006
    Location
    USA
    Posts
    42

    Re: [2005] Contextual Menu Appearing When i dont want it to

    i found this but it removes the whole position thing but it seems to work i dont know

    Madaxe


    Code:
          Select Case node.Text
    
                    Case "Default", "Roll1", "Roll2", "Roll3", "Roll4", "Roll5", "Roll6", "Roll7", "Roll8", "Roll9", "Roll10"
    
                        treeview1.ContextMenuStrip = ContextMenuStrip1
    
                    Case Else
    
                        treeview1.ContextMenuStrip = nothing
    
                End Select

Posting Permissions

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



Click Here to Expand Forum to Full Width