Articles in this section
Category / Section

How to create a customized cell context menu of WinForms Spreadsheet (SfSpreadsheet)?

1 min read

Customize the cell context menu

Spreadsheet provides support to customize the cell context menu. User can add their own custom menu items and add this to the cell context menu of Spreadsheet.


For example, create a custom context menu items such as Insert Row, Insert Column, Delete Row and Delete Column respectively.


public ContextMenuStrip CustomContextmenu()
    var contextMenu = new ContextMenuStrip();
    contextMenu.BackColor = Color.White;
    var Insertrow = new ToolStripMenuItem() { Text = "InsertRow", Height = 26 };
    Insertrow.BackColor = Color.White;
    Insertrow.Click += Insertrow_Click;
    var Deleterow = new ToolStripMenuItem() { Text = "DeleteRow", Height = 26 };
    Deleterow.BackColor = Color.White;
    Deleterow.Click += Deleterow_Click;
    var Insertcolumn = new ToolStripMenuItem() { Text = "Insertcolumn", Height = 26 };
    Insertcolumn.BackColor = Color.White;
    Insertcolumn.Click += Insertcolumn_Click;
    var Deletecolumn = new ToolStripMenuItem() { Text = "Deletecolumn", Height = 26 };
    Deletecolumn.BackColor = Color.White;
    Deletecolumn.Click += Deletecolumn_Click;
    return contextMenu;

Now set this function CustomContextmenu to the CellContextMenu property of Active SpreadsheetGrid in the WorkbookLoaded event of SfSpreadsheet


void spreadsheet_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args)
   spreadsheet.ActiveGrid.CellContextMenuOpening += ActiveGrid_CellContextMenuOpening;


private void ActiveGrid_CellContextMenuOpening(object sender, Syncfusion.Windows.Forms.CellGrid.Helpers.CellContextMenuOpeningEventArgs e)
   e.CellContextMenu = CustomContextmenu();

The following screenshot illustrates the Spreadsheet after create cell context menu  

Show the customize context menu of spreadsheet

Sample: WinForms

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment