Skip to main content
A newer version of this page is available. .

Change the Behavior of the Standard Menu Items

  • 2 minutes to read

Change the Behavior of the Standard Menu Items

Clicking any default item within the standard context menus fires the TreeList.TreeListMenuItemClick event. This event lets you cancel the default actions, or provide your own item handling.

When handling this event, you need to set the event’s Handled parameter to true or false. Setting this parameter to true indicates that you’ve handled this event, and no default processing is required. If the Handled parameter is set to false, the default actions will be performed immediately after your event handler.

Example

The following sample code changes the behavior of the Sort Ascending and Sort Descending items of the column header menu. By default, clicking one of these items sorts the data by the values in the associated column without clearing the previously applied sorting. This allows sorting by multiple columns to be implemented.

In the example, the TreeList.TreeListMenuItemClick event is handled to clear the existing sorting, before the column values are sorted.

using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList;
//...
private void treeList1_TreeListMenuItemClick(object sender, TreeListMenuItemClickEventArgs e) {
   if(e.IsFooter) return;
   TreeList tl = (sender as TreeList);
   if(e.MenuItem.Caption == "Sort Ascending" || e.MenuItem.Caption == "Sort Descending") {
      tl.ClearSorting();
      if(e.MenuItem.Caption == "Sort Ascending") 
         e.Column.SortOrder = SortOrder.Ascending;
      else 
         e.Column.SortOrder = SortOrder.Descending;
      e.Handled = true;
   }
}