Skip to main content
Tab

ASPxGridView.ContextMenuItemVisibility Event

Enables you to dynamically change the visibility and availability of context menu items.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

public event ASPxGridViewContextMenuItemVisibilityEventHandler ContextMenuItemVisibility

Event Data

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

Property Description
Items Gets the collection of items in the context menu.
MenuType Gets the currently displayed context menu‘s type.

The event data class exposes the following methods:

Method Description
SetEnabled(GridViewContextMenuItem, GridViewColumn, Boolean) Allows you to set the availability of a particular item based on the right-clicked column.
SetEnabled(GridViewContextMenuItem, Boolean) Allows you to set the availability of a particular item.
SetEnabled(GridViewContextMenuItem, Int32, Boolean) Allows you to set the availability of a particular item based on the right-clicked row.
SetVisible(GridViewContextMenuItem, GridViewColumn, Boolean) Allows you to set the visibility of a particular item based on the right-clicked column.
SetVisible(GridViewContextMenuItem, Boolean) Allows you to set the visibility of a particular item.
SetVisible(GridViewContextMenuItem, Int32, Boolean) Allows you to set the visibility of a particular item based on the right-clicked row.

Remarks

The ContextMenuItemVisibility event allows you to hide/show and disable/enable context menu items. You can use the event parameter’s properties to access the collection of context menu items (ASPxGridViewContextMenuItemVisibilityEventArgs.Items) and get the displayed menu type (ASPxGridViewContextMenuItemVisibilityEventArgs.MenuType).

Event parameter provides the ASPxGridViewContextMenuItemVisibilityEventArgs.SetVisible and ASPxGridViewContextMenuItemVisibilityEventArgs.SetEnabled methods that allows you to change an item visibility and availability based on the right-clicked row or column.

MVC Example

settings.ContextMenuItemVisibility = (sender, e) =>
{
    if (e.MenuType == GridViewContextMenuType.Rows)
    {
        MVCxGridView gridView = sender as MVCxGridView;
        GridViewContextMenuItem itemExpandAll = e.Items.FindByName("ExpandAll");
        GridViewContextMenuItem itemCollapseAll = e.Items.FindByName("CollapseAll");

        for (int i = 0; i < gridView.VisibleRowCount; i++)
        {
            e.SetVisible(itemExpandAll, i, gridView.IsGroupRow(i));
            e.SetVisible(itemCollapseAll, i, gridView.IsGroupRow(i));
        }
    }
};
See Also