[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
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
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