下面的示例代码改变了 Sort AscendingSort Descending 菜单项 (属于 列标头菜单) 的行为。 在默认情况下,单击其中一个菜单项则根据相关联列中的取值对数据排序,而不清除之前应用的排序。 这样允许根据多个列实现排序。

在本示例中,为了在按照列的取值排序之前清除已有的排序,接管了 TreeList.TreeListMenuItemClick 事件。

C#CopyCode image复制代码
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;
   }
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraTreeList.Columns
Imports DevExpress.XtraTreeList
'...
Private Sub TreeList1_TreeListMenuItemClick(ByVal sender As Object, _
ByVal e As TreeListMenuItemClickEventArgs) Handles TreeList1.TreeListMenuItemClick
   If e.IsFooter Then Exit Sub
   If e.MenuItem.Caption = "Sort Ascending" Or e.MenuItem.Caption = "Sort Descending" Then
      sender.ClearSorting()
      If e.MenuItem.Caption = "Sort Ascending" Then
         e.Column.SortOrder = SortOrder.Ascending
      Else
         e.Column.SortOrder = SortOrder.Descending
      End If
      e.Handled = True
   End If
End Sub