Search code examples
vb.netexceldrop-down-menuvstoribbon

Adding items to Ribbon dropdown using VB.NET


I am new to developing Excel VSTO solutions and need a little help on how to add further items to a dropdown control on the ribbon.

So far I have been able to create a number of items manually and then afterwards change the label of these items using

Globals.Ribbons.Ribbon1.DropDown1.Items(i).Label

Furthermore I found that some recommend using this to add further items to the dropdown control. But I am having a hard time trying to understand how to use it.

Globals.Factory.GetRibbonFactory.CreateRibbonComboBox.Items.Add

I would like to see a sample of how others have done it.


Solution

  • Looks like you're on the right track. You need to first use the factory to create a new RibbonDropDownItem, give the new control the label you want, and then add the control to the parent ComboBox.

    RibbonDropDownItem rdi = 
        Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
    rdi.Label = "My Label";
    Globals.Ribbons.Ribbon1.DropDown1.Items.Add(rdi);