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 add the ContextMenu to the GridTreeControl?

Platform: WPF |
Control: GridTreeControl |
.NET Framework: 4.5 |
Product Version:
Tags: contextmenu

The GridTreeControl provides support to the ContextMenu interactive feature that is used to show the customizable menu for performing some functions in Grid. Here, Sorting, copy and paste operations are performed using ContextMenu.

In the GridTreeControl, you can show the context menu based on some criteria with the help of QueryContextMenuInfo event. To show the context menu by using the QueryContextMenuInfo event, you need to set the EnableContextMenu to true.

You can refer to the following code example to enable the ContextMenu in the grid.




By using the QueryContextMenuInfo event, you can get the details about cells like CellValue, CellType, column index, and row index. Based on those values, you can create your own ContextMenu.

In the following code example, ContextMenu for a grid is created based on the row index in the QueryContextMenuInfo event. Refer to the following code example to add the menu items in the ContextMenu based on the rowindex.




In the QueryContextMenuInfo event, when the row index is 0 (Header row), then the SortColumn menu item is added to the ContextMenu. For the other rows, Copy and Paste menu items are added. Refer to the following code example to perform the operations on clicking the menu items in the ContextMenu by using the Commands and CommandParameter of a menu item.



On clicking the menu items, the following operations are performed.

  • Sort Column - Corresponding column is sorted.
  • Copy - Copy the selected node.
  • Paste - Copied node is pasted in the grid.

When you open the ContextMenu in the Header row, then the ContextMenu is displayed as follows.

Figure 1: Menu Item SortColumn added to ContextMenu

When you open the ContextMenu in other rows, then the ContextMenu is displayed as follows:

Figure 2: Copy, Paste Menu Items are added to Context Menu

Sample Link: AddContextMenuIn_GridTreeControl

2X faster development

The ultimate WPF 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