DevExpress自定义Spreadsheetcontrol 单元格右键菜单

using DevExpress.XtraSpreadsheet;
using DevExpress.XtraSpreadsheet.Commands;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraSpreadsheet.Menu;

        private void spreadsheetControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
        {
            if (e.MenuType == SpreadsheetMenuType.Cell)
            {
                // Remove the "Clear Contents" menu item.
                e.Menu.RemoveMenuItem(SpreadsheetCommandId.FormatClearContentsContextMenuItem);

                // Disable the "Hyperlink" menu item.
                e.Menu.DisableMenuItem(SpreadsheetCommandId.InsertHyperlinkContextMenuItem);

                // Create a menu item for the Spreadsheet command, which inserts a picture into a worksheet.
                ISpreadsheetCommandFactoryService service = (ISpreadsheetCommandFactoryService)spreadsheetControl1.GetService(typeof(ISpreadsheetCommandFactoryService));
                SpreadsheetCommand cmd = service.CreateCommand(SpreadsheetCommandId.InsertPicture);
                SpreadsheetMenuItemCommandWinAdapter menuItemCommandAdapter = new SpreadsheetMenuItemCommandWinAdapter(cmd);
                SpreadsheetMenuItem menuItem = (SpreadsheetMenuItem)menuItemCommandAdapter.CreateMenuItem(DevExpress.Utils.Menu.DXMenuItemPriority.Normal);
                menuItem.BeginGroup = true;
                e.Menu.Items.Add(menuItem);

                // Insert a new item into the Spreadsheet popup menu and handle its click event.
                SpreadsheetMenuItem myItem = new SpreadsheetMenuItem("My Menu Item", new EventHandler(MyClickHandler));
                e.Menu.Items.Add(myItem);
            }
        }

        public void MyClickHandler(object sender, EventArgs e)
        {
            MessageBox.Show("My Menu Item Clicked!");
        }

你可能感兴趣的:(DevExpress自定义Spreadsheetcontrol 单元格右键菜单)