# Displaying Context Menu at Runtime

Spread allows you to display a context menu at runtime as in Spread Designer. Hence, removing the need to attach with ribbon control.

## Content



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](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.LegacyBehaviors.html) 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 | ![](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/context-menu-cell.png) |
| Row Header | ![](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/contextmenu-rowheader.png) |
| Column Header | ![](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/context_menufor_column_header.png) |
| Sheet Corner | ![](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/contextmenu-sheetcorner.png) |

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

```csharp
// Adding context menu
fpSpread1.ContextMenuStrip = new SpreadContextMenuStrip(); 
```

```vbnet
' 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 | ![](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/context_menu_for_%20cell_design_mode1.png) |
| Column Header | ![](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/context%20menu%20for%20column_design_mode1.png) |

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

```csharp
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);
    }
}
```

```vbnet
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.

```csharp
// Context menu will not be shown  
fpSpread1.ContextMenuStrip = null;   
```

```vbnet
' 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](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell)

[Using Edit Mode and Focus](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cell-focus)

[Customizing User Selection and Deselection of Data](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-interactselection)

[Using Drag Operations to Fill Cells](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cell-dragops)

[Using Double Click to Fill Cells](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cell-clicktofill)

[Using Validation](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cellvalid)

[Using Visible Indicators in the Cell](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cell-indicators)

[Customizing Undo and Redo Actions](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-undoredo)

[Customizing Interaction Based on Events](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cntrlevents)

[Adding Custom Context Menu to a Component](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-interactcell/spwin-cntrlcontextmenu)