ASPxClientSpreadsheet.PopupMenuShowing Event
Occurs before the context menu is displayed and allows menu customization.
Declaration
PopupMenuShowing: ASPxClientEvent<ASPxClientSpreadsheetPopupMenuShowingEventHandler<ASPxClientSpreadsheet>>
Event Data
The PopupMenuShowing event's data class is ASPxClientSpreadsheetPopupMenuShowingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
cancel | Specifies whether to cancel the related action (for example, row edit, export). Inherited from ASPxClientCancelEventArgs. |
menuItems | Provides access to a collection of menu items in the context menu being invoked. |
menuType | Gets the currently displayed context menu’s type. |
Remarks
By handling the PopupMenuShowing client-side event, you can perform the following actions with the Spreadsheet’s context menu:
- Identify a worksheet element (e.g., a cell, row or column header, chart or picture) for which the context menu is invoked (use the ASPxClientSpreadsheetPopupMenuShowingEventArgs.menuType property);
- Prevent the context menu from being displayed (use the ASPxClientCancelEventArgs.cancel property);
- Manipulate menu items - add new items, remove or disable existing ones (use the ASPxClientSpreadsheetPopupMenuShowingEventArgs.menuItems property).
See Online Demo: Context Menu Customization
Example
This sample illustrates how to prevent the context menu display for worksheet tabs and to add a custom menu item to the context menu displayed for row headings.
The context menu is dynamically processed in the ASPxClientSpreadsheet.PopupMenuShowing
client event. The current context menu type is determined through the ASPxClientSpreadsheetPopupMenuShowingEventArgs.menuType property. A custom menu item is implemented as a new item containing a custom command name.
Clicks on the custom menu item with the custom command name are processed by using the ASPxClientSpreadsheet.CustomCommandExecuted client event. Within its handler, the activated custom command is identified and the corresponding action (insertion of a row with the current date and time values) is performed through a callback to the server.
using DevExpress.Spreadsheet;
using DevExpress.Web;
using DevExpress.Web.ASPxSpreadsheet;
using DevExpress.Web.ASPxSpreadsheet.Internal;
using DevExpress.Web.Office;
using DevExpress.Web.Office.Internal;
...
protected void Page_Load(object sender, EventArgs e) {
if(!Page.IsPostBack) {
string filePath = Server.MapPath("~/App_Data/WorkDirectory/DayBook.xlsx");
spreadsheet.Open(filePath);
}
}
protected void spreadsheet_Callback(object sender, CallbackEventArgsBase e) {
IWorkbook currentWorkbook = spreadsheet.Document;
Worksheet currentWorksheet = currentWorkbook.Worksheets.ActiveWorksheet;
currentWorkbook.BeginUpdate();
currentWorksheet.InsertCells(currentWorksheet.Selection, InsertCellsMode.EntireRow);
FillInTemplateValues(currentWorksheet);
currentWorkbook.EndUpdate();
}
void FillInTemplateValues(Worksheet currentWorksheet) {
int currentRowIndex = currentWorksheet.Selection.TopRowIndex;
currentWorksheet.Cells[currentRowIndex, 1].Value = DateTime.Now.Date;
currentWorksheet.Cells[currentRowIndex, 2].Value = DateTime.Now.TimeOfDay;
currentWorksheet.Cells[currentRowIndex, 2].NumberFormat = "h:mm";
}