windowsforms-5700-controls-and-libraries-tree-list-feature-center-context-menus-change-the-behavior-of-the-standard-menu-items.md
A click on a menu item in standard context menus raises the TreeList.TreeListMenuItemClick event. You can handle this event to:
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;
}
}
Private Sub treeList1_TreeListMenuItemClick(ByVal sender As Object, ByVal e As TreeListMenuItemClickEventArgs)
If e.MenuItem.Caption = "Sort Ascending" OrElse e.MenuItem.Caption = "Sort Descending" Then
e.Column.TreeList.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