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. 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") {
      if(e.MenuItem.Caption == "Sort Ascending") 
         e.Column.SortOrder = SortOrder.Ascending;
         e.Column.SortOrder = SortOrder.Descending;
      e.Handled = true;