[]
        
(Showing Draft Content)

Displaying Context Menu at Runtime

Spread allows you to display the context menu as in Spread Designer at runtime. Hence, removing the need to attach it with ribbon control. This can be done by setting Spread’s ContextMenuStrip property with a new instance of the SpreadContextMenuStrip. Displaying the context menu at runtime works only when LegacyBehaviors.Style is excluded from LegacyBehaviors enum.

type=note

There is no default context menu in Spread.

The table below depicts different context menu displayed on right clicking specific parts of Spread.

Area Clicked Context Menu Items
Cell
Row Header
Column Header
Sheet Corner

Use the following code to display context menu in Spread at runtime.

// Adding context menu
fpSpread1.ContextMenuStrip = new SpreadContextMenuStrip(); 
' Adding context menu
FpSpread1.ContextMenuStrip = New SpreadContextMenuStrip()

You can also display context menu like design mode on a Cell and Column Header as displayed below.

Area Clicked Design Mode Context Menu Items
Cell
Column Header

The following code displays the context menu as that of design mode in Spread at runtime.

fpSpread1.BeforeRightClick += FpSpread1_BeforeRightClick;  
// For changing ContextMenu as design mode ContextMenu
private void FpSpread1_BeforeRightClick(object sender, BeforeRightClickEventArgs e)
{
    if (e.ContextMenuStrip is SpreadContextMenuStrip spreadContext)
    {
        ContextMenuType contextMenuType = e.ContextMenuType;
        spreadContext.GenerateMenuItems(fpSpread1, contextMenuType, true);
    }
}
AddHandler FpSpread1.BeforeRightClick, AddressOf FpSpread1_BeforeRightClick
' For changing ContextMenu as design mode ContextMenu
Private Sub FpSpread1_BeforeRightClick(ByVal sender As Object, ByVal e As BeforeRightClickEventArgs) Handles FpSpread1.BeforeRightClick
     Dim spreadContext As SpreadContextMenuStrip = TryCast(e.ContextMenuStrip, SpreadContextMenuStrip)
     If spreadContext IsNot Nothing Then
         Dim contextMenuType As ContextMenuType = e.ContextMenuType
         spreadContext.GenerateMenuItems(FpSpread1, contextMenuType, True)
     End If
End Sub

Although, context menu does not appear automatically, but if used then you can remove it later by following code.

// Context menu will not be shown  
fpSpread1.ContextMenuStrip = null;   
' Context menu will not be shown
FpSpread1.ContextMenuStrip = Nothing

Limitation

Spread does not support built-in context menu during design time.

See Also

Customizing Interaction in Cells

Using Edit Mode and Focus

Customizing User Selection and Deselection of Data

Using Drag Operations to Fill Cells

Using Double Click to Fill Cells

Using Validation

Using Visible Indicators in the Cell

Customizing Undo and Redo Actions

Customizing Interaction Based on Events

Adding Custom Context Menu to a Component