Right Click to Select on TreeView

P

Patrick

This may be a simple question but how can I make the tree change the
selected node... on a right click .. in addition to the left click?

What I want is to filter my context menu based on the type of node selected
but the left click doesn't seem to change the selected node.

Thanks,
 
H

Herfried K. Wagner [MVP]

* "Patrick said:
This may be a simple question but how can I make the tree change the
selected node... on a right click .. in addition to the left click?

\\\
Private Sub TreeView1_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles TreeView1.MouseUp
If e.Button = MouseButtons.Right Then
Dim n As TreeNode = Me.TreeView1.GetNodeAt(e.X, e.Y)
If Not n Is Nothing Then
Me.TreeView1.SelectedNode = n
Me.MenuItem1.Text = n.Text
Else
Me.MenuItem1.Text = "(no item selected)"
End If
Me.ContextMenu1.Show(Me.TreeView1, New Point(e.X, e.Y))
End If
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top