Skip to main content

PopupMenuShowingEventArgs.HitInfo Property

Provides access to information about the clicked visual element.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v23.2.dll

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

Declaration

public TreeListHitInfo HitInfo { get; }

Property Value

Type Description
TreeListHitInfo

An object that contains information about a visual element.

Remarks

The Tree List shows a context menu when the user right-clicks within the following areas:

The HitInfo and MenuType event arguments allow you to determine the clicked visual element and the type of the menu that is about to be displayed.

Example

The PopupMenuShowing event is raised before a context menu is shown and allows you to customize it. The HitInfo event argument is set to Empty when a user right-clicked the empty area.

The code below shows how to add the Full Collapse and Full Expand commands to the empty-area context menu.

image

using DevExpress.Utils.Menu;
using DevExpress.Utils.Svg;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Localization;

treeList1.PopupMenuShowing += OnPopupMenuShowing;

void OnPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    TreeList treeList = sender as TreeList;
    if(e.HitInfo.HitInfoType == HitInfoType.Empty) {
        string expandAllCaption = TreeListLocalizer.Active.GetLocalizedString(TreeListStringId.MenuNodeExpandAll);
        DXMenuItem expandAll = new DXMenuItem(expandAllCaption, (ss, ee) => treeList.ExpandAll());
        expandAll.ImageOptions.SvgImage = CommonSvgImages.Get(CommonSvgImages.Column.ExpandAll);
        e.Menu.Items.Add(expandAll);
        string collapseAllCaption = TreeListLocalizer.Active.GetLocalizedString(TreeListStringId.MenuNodeCollapseAll);
        DXMenuItem collapseAll = new DXMenuItem(collapseAllCaption, (ss, ee) => treeList.CollapseAll());
        collapseAll.ImageOptions.SvgImage = CommonSvgImages.Get(CommonSvgImages.Column.CollapseAll);
        e.Menu.Items.Add(collapseAll);
        e.Allow = true;
    }
}
See Also