Skip to main content

How to: Change the behavior of the standard menu items

The following sample code changes the behavior of the Sort Ascending and Sort Descending items of the column header menu. These items no longer clear previously applied sorting. End-users can easily sort nodes by multiple columns.

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