Set up an NContextMenu for a TreeNode in an NTreeView

Applies to: Nevron User Interface for .NET

How to set up an NContextMenu for a TreeNode in an NTreeView?

You should display the context menu manually since there is no such property as ContextMenu per TreeNode. You may use the following code:

[C#]
//hook to the tree-view's MouseUp notification
this.nTreeView1.MouseUp += new MouseEventHandler(OnTreeView_MouseUp);
  
//inside the body of the handler method put the following code
private void OnTreeView_MouseUp(object sender, MouseEventArgs e)
{
    if(e.Button == MouseButtons.Right)
    {
        if(myNode.Bounds.Contains(e.X, e.Y))   
        {
            //the Show method of the context menu requires screen coordinates 
            Point screen = Control.MousePosition;
            myContextMenu.Show(screen);   
        }
    }
}

[VB.NET]
'hook to the tree-view's MouseUp notification
Me.nTreeView1.MouseUp += New MouseEventHandler(OnTreeView_MouseUp)
  
'inside the body of the handler method put the following code
Private Sub OnTreeView_MouseUp(sender As Object, e As MouseEventArgs)
    If e.Button = MouseButtons.Right Then
        If myNode.Bounds.Contains(e.X, e.Y) Then
            'the Show method of the context menu requires screen coordinates 
            Dim screen As Point = Control.MousePosition
            myContextMenu.Show(screen)
        End If
    End If
End Sub

Article ID: 109, Created On: 11/1/2010, Modified: 11/15/2010