-1

I can't add items to dropdown controller at runtime in the Ribbon class. However, looks like many topics and even msdn resolve it using Globals class properties.

https://msdn.microsoft.com/en-us/library/bb772088.aspx

The firt example on this msdn page doesn't work for me. I can't reach the dropDown or any other controller (button, comboBox, etc.).

Here is my .xml file:

<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
 <ribbon>
  <tabs>
   <tab id="LFET" label="LFET(new)">
    <group id="Data" label="Data">
     <dropDown id="DropdownList" label="Dropdownlist1" visible="true">
     </dropDown>
    </group>
   </tab>
  </tabs>
 </ribbon>
</customUI>

And the .cs where i'm trying to access the dropDown item:

namespace TEST
{
    [ComVisible(true)]
    public class TESTRibbon : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public void DropdownList()
        {
            //No way to access my custom ribbon like that.
            Globals.Ribbons.Ribbon.Dropdownlist1.Items.Add();
        }
    }
}

Regards,

Chefty
  • 149
  • 1
  • 13
  • 2
    The approach differs depending on whether RibbonXML or the VSTO Ribbon Designer is used - the two can't be mixed. Ribbon XML needs "callbacks" (same as for VBA, for example) in the Ribbon.cs file. If you use the Ribbon Designer then VSTO sets the callbacks up in the background and you can use the `public void DropdownList()` approach you show in your code. In the VSTO documentation your starting point is https://msdn.microsoft.com/en-us/library/aa942866.aspx That contains links to the 3 Parts of an article on customizing the Ribbon which provides the rest of what you need. – Cindy Meister Jun 21 '16 at 17:19

1 Answers1

1

I know I've had issues manipulating the ribbon directly. One thing might solve it is to Invalidate the ribbon.

Alternatively, you can make it dynamic, and have the values come from the code. I do this in my Word Add-In and it works fine. If you change the values probably have to invalidate it afterwards (I don't change mine after setting it the first time).

<dropDown id="mycustomid" showLabel="false" onAction="onAction" getSelectedItemIndex="getSelected"
          getItemCount="getCount" getItemID="getID" getItemLabel="getLabel" getEnabled="getEnabled"
          screentip="whatever" supertip="whatever" />


public void onAction(IRibbonControl control, string id, int index)
{
}

public int getSelected(IRibbonControl control)
{
}

public int getCount(IRibbonControl control)
{
}

public string getID(IRibbonControl control, int index)
{
}

public string getLabel(IRibbonControl control, int index)
{
}
Chris
  • 3,400
  • 1
  • 27
  • 41
  • You just CANNOT manipulate the ribbon directly. The XML is queried by the Office only ONCE at the startup. What issues are you talking about? The dynamic callbacks is the only way. – Nikolay Jun 17 '16 at 20:56
  • That is exactly what I mean - I've never been able to do it, yet that article in the question is talking about how to do exactly that. – Chris Jun 20 '16 at 13:37