Back to Devexpress

TreeList.TreeListMenuItemClick Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-8b029b24.md

latest4.9 KB
Original Source

TreeList.TreeListMenuItemClick Event

Provides the ability to perform custom handling of a context menu item click.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
[DXCategory("Behavior")]
public event TreeListMenuItemClickEventHandler TreeListMenuItemClick
vb
<DXCategory("Behavior")>
Public Event TreeListMenuItemClick As TreeListMenuItemClickEventHandler

Event Data

The TreeListMenuItemClick event's data class is TreeListMenuItemClickEventArgs. The following properties provide information specific to this event:

PropertyDescription
AutoFilterConditionReturns the clicked Automatic Filtering Row condition.
ColumnGets the column against whose header or footer the context menu has been activated.
HandledGets or sets a value indicating whether default menu item click processing is prohibited.
IsFooterGets whether an item in the footer summary’s context menu has been clicked.
MenuItemGets the clicked menu item.
MenuTypeGets the type of menu whose item has been clicked.
SummaryFormatGets or sets the format of summary value displayed for the column.
SummaryTypeGets or sets the summary type which is about to be applied to the column.

Remarks

The TreeListMenuItemClick event fires immediately after a context menu item has been clicked and before this click has been processed. It enables you to perform additional processing for a menu item click. For instance, it can be used to apply custom formatting to summary values when summary type is changed via a context menu.

There are three kinds of context menus provided by the TreeList control. Use the TreeList.OptionsMenu property to control the availability of menus to users.

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.

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

See Also

OptionsMenu

PopupMenuShowing

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace