Pop-up Menus

  • 3 minutes to read

The Spreadsheet has several types of context (pop-up) menus which are invoked when the user clicks different visual objects. The SpreadsheetControl provides the SpreadsheetControl.MenuCustomizations property and the SpreadsheetControl.PopupMenuShowing event which allow you to customize context menus by adding or removing items.

Context Menus Overview

Menu Type Appearance Description
SpreadsheetMenuType.AutoFilter SpreadsheetMenuTypeAutoFilter Specifies a context menu which can be invoked by clicking the AutoFilter drop-down arrow.
SpreadsheetMenuType.Cell SpreadsheetMenuTypeCell Specifies a context menu which can be invoked by right-clicking any cell in a worksheet.
SpreadsheetMenuType.Chart SpreadsheetMenuTypeChart Specifies a context menu which can be invoked by right-clicking a chart in a worksheet.
SpreadsheetMenuType.ColumnHeading SpreadsheetMenuTypeColumnHeading Specifies a context menu which can be invoked by right-clicking a column header.
SpreadsheetMenuType.DrawingObjects SpreadsheetMenuTypeDrawingObjects Specifies a context menu which can be invoked by right-clicking a drawing object when a worksheet contains several drawing objects, such as pictures or charts.
SpreadsheetMenuType.Picture SpreadsheetMenuTypePicture Specifies a context menu which can be invoked by right-clicking a picture embedded in a worksheet.
SpreadsheetMenuType.PivotTable SpreadsheetMenuTypePivotTable Specifies a context menu which can be invoked by right-clicking any cell in a pivot table.
SpreadsheetMenuType.PivotTableAutoFilter SpreadsheetMenuTypePivotTableAutoFilter Specifies a context menu which can be invoked by clicking the AutoFilter drop-down arrow on the row or column label of a pivot table.
SpreadsheetMenuType.RowHeading SpreadsheetMenuTypeRowHeading Specifies a context menu which can be invoked by right-clicking a row header.
SpreadsheetMenuType.SelectAllButton SpreadsheetMenuTypeSelectAllButton Specifies a context menu which can be invoked by right-clicking the Select All button in the upper-left corner of a worksheet.
SpreadsheetMenuType.SheetTab SpreadsheetMenuTypeSheetTab Specifies a context menu which can be invoked by right-clicking a worksheet tab.

Customizing Context Menus in XAML

This example demonstrates how to use the SpreadsheetMenuCustomization.Customizations property to add custom items to the popup menu of the SpreadsheetControl or remove the existing ones. Use the SpreadsheetMenuCustomization.MenuType property to determine the visual element for which the popup menu is invoked.

<dxb:BarManager x:Name="barManager1" ToolbarGlyphSize="Small">
    <dxb:BarManager.Items>
        <dxb:BarButtonItem
            x:Name="customNewFile"
            Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}"
            Content="Custom Create New File" />
        <dxb:BarButtonItem
            x:Name="customMergeCells"
            Command="{Binding EditingMergeAndCenterCells, Mode=OneTime, Source={StaticResource commands}}"
            Content="Custom Merge Cells" />
    </dxb:BarManager.Items>
    <Grid>
        <dxsps:SpreadsheetControl
            x:Name="spreadsheetControl1"
            BarManager="{Binding ElementName=barManager1, Mode=OneTime}"
            PopupMenuShowing="SpreadsheetControlPopupMenuShowing">
            <dxsps:SpreadsheetControl.MenuCustomizations>
                <dxsps:SpreadsheetMenuCustomization MenuType="Cell">
                    <dxb:BarButtonItemLink dxb:BarItemLinkActionBase.ItemLinkIndex="0">
                        <dxb:BarButtonItemLink.BarItemName>
                            customMergeCells
                        </dxb:BarButtonItemLink.BarItemName>
                    </dxb:BarButtonItemLink>
                </dxsps:SpreadsheetMenuCustomization>
                <dxsps:SpreadsheetMenuCustomization>
                    <dxb:BarButtonItemLink dxb:BarItemLinkActionBase.ItemLinkIndex="1">
                        <dxb:BarButtonItemLink.BarItemName>
                            customNewFile
                        </dxb:BarButtonItemLink.BarItemName>
                    </dxb:BarButtonItemLink>
                </dxsps:SpreadsheetMenuCustomization>
                <dxsps:SpreadsheetMenuCustomization>
                    <dxb:BarItemLinkSeparator dxb:BarItemLinkActionBase.ItemLinkIndex="2" />
                </dxsps:SpreadsheetMenuCustomization>
                <dxsps:SpreadsheetMenuCustomization MenuType="ColumnHeading">
                    <dxsps:RemoveSpreadsheetCommandAction 
                        Id="{x:Static dxspscore:SpreadsheetCommandId.HideColumnsContextMenuItem}" />
                    <dxsps:RemoveSpreadsheetCommandAction 
                        Id="{x:Static dxspscore:SpreadsheetCommandId.UnhideColumnsContextMenuItem}" />
                </dxsps:SpreadsheetMenuCustomization>
            </dxsps:SpreadsheetControl.MenuCustomizations>
        </dxsps:SpreadsheetControl>
    </Grid>
</dxb:BarManager>

Customizing Context Menus Dynamically

Handle the SpreadsheetControl.PopupMenuShowing event to customize context menus at runtime.

See Also