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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create a customized cell context menu of SfSpreadsheet

Platform: WPF |
Control: SfSpreadsheet
Tags: context-menu

SfSpreadsheet 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 SfSpreadsheet.


For example


Create a custom context menu items such as Insert Row, Insert Column, Delete Row and Delete Column respectively.



public ContextMenu CustomContextmenu()
var contextMenu = new ContextMenu();
contextMenu.Background = Brushes.White;
var Insertrowicon = new Image() { Source = new BitmapImage(new Uri(@"..\..\Icon\insertrow.png",
                                                               UriKind.Relative)) };   
var Insertrow = new MenuItem() { Header = "InsertRow", Height = 26 };
Insertrow.BorderThickness = new Thickness(0);
Insertrow.Background = Brushes.White;
Insertrow.Icon = Insertrowicon;
Insertrow.Click += Insertrow_Click;
var Deleterowicon = new Image() { Source = new BitmapImage(new Uri(@"..\..\Icon\deleterow.png", 
                                                               UriKind.Relative)) };
var Deleterow = new MenuItem() { Header = "DeleteRow", Height = 26 };
Deleterow.BorderThickness = new Thickness(0);
Deleterow.Background = Brushes.White;
Deleterow.Icon = Deleterowicon;
Deleterow.Click += Deleterow_Click;
var Insertcolumnicon = new Image() { Source = new BitmapImage(new Uri(@"..\..\Icon\inscol.png",
                                                                  UriKind.Relative)) };      
var Insertcolumn = new MenuItem() { Header = "Insertcolumn", Height = 26 };
Insertcolumn.BorderThickness = new Thickness(0);
Insertcolumn.Background = Brushes.White;
Insertcolumn.Icon = Insertcolumnicon;
Insertcolumn.Click += Insertcolumn_Click;
var Deletecolumnicon = new Image() { Source = new BitmapImage(new Uri(@"..\..\Icon\delcol.png",
                                                                  UriKind.Relative)) }; 
var Deletecolumn = new MenuItem() { Header = "Deletecolumn", Height = 26 };
Deletecolumn.BorderThickness = new Thickness(0);
Deletecolumn.Background = Brushes.White;
Deletecolumn.Icon = Deletecolumnicon;
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.CellContextMenu = CustomContextmenu();


The following screenshot illustrates the SfSpreadsheet after create cell context menu  



Sample link:





2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment
Muthukumar A [Syncfusion]
Mar 21, 2018

Cell not opening CustomContextMenu. Need to set any properties?


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