TreeView And ContextMenu Question

T

Tiraman :-\)

Hi Everyone,

i have a treeview that look like this.

Node1
nodechild1.1
nodechild1.2
nodechild1.3
Node2
nodechild2.1
nodechild2.2

and so on

and i would like to bind one contextmenu to the root nodes (Node1, Node2)
and other contextmenu to the Childs.

how can i do that ?

Thanks,

T :)
 
H

Herfried K. Wagner [MVP]

* "Tiraman :-\) said:
i have a treeview that look like this.

Node1
nodechild1.1
nodechild1.2
nodechild1.3
Node2
nodechild2.1
nodechild2.2

and so on

and i would like to bind one contextmenu to the root nodes (Node1, Node2)
and other contextmenu to the Childs.

\\\
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
///
 
T

Tiraman :-\)

Thanks!

Herfried K. Wagner said:
\\\
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