Skip to main content

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;
   }
}