AddyProg
AddyProg

Reputation: 3050

Custom context menu not visible in Excel (VSTO C#)

trying to create some options in excel cell right click menu using custom UI. Here is the XML

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
  </ribbon>
  <contextMenus>
    <contextMenu idMso="ContextMenuText">
      <button id="mybutton" onAction="ShowMessageClick" getLabel="GetSynchronisationLabel"/>

    </contextMenu>
  </contextMenus>
</customUI>

And here is ThisAddin.cs

namespace DemoAddin
{
    public partial class ThisAddIn
    {


        public string GetSynchronisationLabel(Office.IRibbonControl control)
        {
            return "Synchronize";
        }

        public void ShowMessageClick(Office.IRibbonControl control)
        {
            MessageBox.Show("You've clicked the synchronize context menu item", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new Ribbon2();

        }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {



        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

the options i add using this code are not visible in context menu.

Upvotes: 0

Views: 783

Answers (1)

AddyProg
AddyProg

Reputation: 3050

simply changing idMso of context menu from ContextMenuText to "ContextMenuCell" solved the issue.

<contextMenus>
    <contextMenu idMso="ContextMenuCell">
      <button id="mybutton" onAction="ShowMessageClick" getLabel="GetSynchronisationLabel"/>

    </contextMenu>
  </contextMenus>

Upvotes: 3

Related Questions