Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Change the Behavior of Standard Menu Items

A click on a menu item in standard context menus raises the TreeList.TreeListMenuItemClick event. You can handle this event to:

  • Execute custom actions.
  • Cancel the default action (set the e.Handled property to true).

#Example

The following code sample changes the behavior of Sort Ascending and Sort Descending items in the column header menu. The default items do not clear the applied sorting. The TreeList.TreeListMenuItemClick event handler clears the existing sorting before the sort operation.

void treeList1_TreeListMenuItemClick(object sender, TreeListMenuItemClickEventArgs e) {
   if (e.MenuItem.Caption == "Sort Ascending" || e.MenuItem.Caption == "Sort Descending") {
         e.Column.TreeList.ClearSorting();
         if (e.MenuItem.Caption == "Sort Ascending")
            e.Column.SortOrder = SortOrder.Ascending;
         else
            e.Column.SortOrder = SortOrder.Descending;
         e.Handled = true;
   }
}