Skip to main content
All docs
V24.1

ASPxClientGantt.ContextMenu Event

Occurs when a user right-clicks a task or dependency to open the context menu.

Declaration

ContextMenu: ASPxClientEvent<ASPxClientGanttContextMenuEventHandler<ASPxClientGantt>>

Event Data

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

Property Description
cancel Specifies whether to cancel the related action (for example, row edit, export). Inherited from ASPxClientCancelEventArgs.
htmlEvent Gets the DHTML event object that contains information about the processed event.
objectInfo Gets information about the right-clicked object.

Remarks

The ContextMenu event enables you to create a custom context menu.

Follow the steps below to create a custom context menu:

  • Handle the ContextMenu event.

  • Set the e.cancel argument of the ContextMenuCustomization event to true to prevent the built-in context menu from showing.

To customize items of the built-in context menu, use the ContextMenuCustomization event.

Run Demo: ASPxGantt - Context Menu Run Demo: MVCxGantt - Context Menu

Example

The example below illustrates how to show the pop-up menu when a user right-clicks the control.

Web Forms:

<dx:ASPxGantt ID="Gantt" ClientInstanceName="clientGantt" >
    <ClientSideEvents 
        ContextMenu="function(s, e) { menu.ShowAtPos(e.htmlEvent.x,e.htmlEvent.y); }" 
        ContextMenuCustomization="function(s, e) { e.cancel = true; }"
    />
</dx:ASPxGantt>

<dx:ASPxPopupMenu runat="server" ID="popup" ClientInstanceName="menu">
    <Items>
        <dx:MenuItem Text="Item1" />
        <dx:MenuItem Text="Item2" />
    </Items>        
</dx:ASPxPopupMenu>

MVC:

@Html.DevExpress().Gantt(settings => {
    settings.Name = "gantt";
    settings.ClientSideEvents.ContextMenuCustomization = "function (s, e) { e.cancel = true; }";
    settings.ClientSideEvents.ContextMenu = "function (s, e) { popup.ShowAtPos(e.htmlEvent.x,e.htmlEvent.y); }";
    ...
}).Bind(
    GanttDataProvider.Tasks, GanttDataProvider.Dependencies, 
    GanttDataProvider.Resources, GanttDataProvider.ResourceAssignments
).GetHtml()

@Html.DevExpress().PopupMenu(
    settings.Name = "popup";
    settings.Items.Add(item => {
        item.Text = "Item 1";
        item.Name = "Item 2";
    });
).GetHtml()
See Also