Which node on the tree view was clicked?

D

Dan

Anyone have any code to place in this procedure to determine what node
on my tree view was clicked?

Private Sub TreeView1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TreeView1.Click

End Sub

Thanks in advance.
 
J

Jason L James

Hi Dan,

try

MsgBox(TreeView1.SelectedNode.Text)

you can return any of the node properties this way, not
just text.

Good luck,

Jason
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Dan) scripsit:
Anyone have any code to place in this procedure to determine what node
on my tree view was clicked?

\\\
Private Sub TreeView1_MouseUp( _
ByVal sender As Object, _
ByVal e As 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