Adding items to RibbonDropDown at runtime

CodeMinion picture CodeMinion · Apr 13, 2011 · Viewed 21.9k times · Source

So I have a dropdown menu in a ribbon with contents that can be changed while it is being used. Outlook is also happy to let me 'add' or 'insert' items into it, as long as I do not add more than 1 item.

If I try to, I'll be told that the index is out of bounds rather than expanding the upper bounds for me.

I find that if I insert it into the collection in the designer portion of the code, it will work fine, but designer code is only run once, unless I Dispose the ribbon and re-create it.

Any ideas regarding how I can get this working

Answer

sadanand sudeer picture sadanand sudeer · Aug 9, 2011

Try this. This should work for you.

RibbonDropDownItem item 
      = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
item.Label = "First Name";
this.cbRecent.Items.Add(item);