Back to Devexpress

ASPxGridView.ContextMenuItemVisibility Event

aspnet-devexpress-dot-web-dot-aspxgridview-d03dea09.md

latest5.0 KB
Original Source

ASPxGridView.ContextMenuItemVisibility Event

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

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewContextMenuItemVisibilityEventHandler ContextMenuItemVisibility
vb
Public Event ContextMenuItemVisibility As ASPxGridViewContextMenuItemVisibilityEventHandler

Event Data

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

PropertyDescription
ItemsGets the collection of items in the context menu.
MenuTypeGets the currently displayed context menu‘s type.

The event data class exposes the following methods:

MethodDescription
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

csharp
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

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace