1 Attachment(s)
[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:mad:
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
dont know the sollution to your problem, but why not use a select case instead of all those ifelse statements?
Re: [2005] Contextual Menu Appearing When i dont want it to
Can you give me an example
thks
Madaxe
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
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
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.
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