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. Image for the cookie policy date
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

Show context menu on key selection

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


//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.


'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.
    End If
End Sub


Show context menu under the selected treenode

Figure 1: ContextMenuStripEx seen under the selected TreeNodeAdv


C#: TreeViewAdv_ContextMenu_C#

VB: TreeViewAdv_ContextMenu_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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