)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to show the context menu on key selection in the WinForms TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: August 31, 2015 |
Last Revised Date: February 4, 2020

Show context menu on key selection

In the TreeViewAdv, Context Menu is shown on key selection by handling the KeyUp event.

C#

//The event is raised when pressed key is released.
this.treeViewAdv1.KeyUp += new KeyEventHandler(treeViewAdv1_KeyUp);
void treeViewAdv1_KeyUp(object sender, KeyEventArgs e)
{
    if(e.KeyValue == 93)
    {
       //Specifies the location where Context menu needs to be shown. 
       int x = treeViewAdv1.SelectedNode.TextBounds.X;
       int y = treeViewAdv1.SelectedNode.Bounds.Y + treeViewAdv1.SelectedNode.Bounds.Height;
       Point point = new Point(x, y);
       Point ContextPoint = treeViewAdv1.PointToScreen(point);
       //Shows the ContextMenuStripEx.
       this.contextMenuStripEx1.Show((ContextPoint));
    }
}

VB

'The event is raised when pressed key is released.
AddHandler treeViewAdv1.KeyUp, AddressOf treeViewAdv1_KeyUp
Private Sub treeViewAdv1_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs)
    If e.KeyValue = 93 Then
       'Specifies location where Context menu needs to be shown. 
       Dim x As Integer = treeViewAdv1.SelectedNode.TextBounds.X
       Dim y As Integer = treeViewAdv1.SelectedNode.Bounds.Y + treeViewAdv1.SelectedNode.Bounds.Height
       Dim point As New Point(x, y)
       Dim ContextPoint As Point = treeViewAdv1.PointToScreen(point)
       'Shows the ContextMenuStripEx.
       Me.contextMenuStripEx1.Show((ContextPoint))
    End If
End Sub

 

Show context menu under the selected treenode

Figure 1: ContextMenuStripEx seen under the selected TreeNodeAdv

Samples:

C#: TreeViewAdv_ContextMenu_C#

VB: TreeViewAdv_ContextMenu_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon