)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: Spreadsheet |
Published Date: April 26, 2016 |
Last Revised Date: January 27, 2020
Tags: context-menu

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.

C#

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

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

C#

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

C#

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon