Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding items to RibbonDropDown at runtime

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

like image 546
CodeMinion Avatar asked Apr 13 '11 03:04

CodeMinion


3 Answers

Try this. This should work for you.

RibbonDropDownItem item 
      = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
item.Label = "First Name";
this.cbRecent.Items.Add(item);
like image 146
sadanand sudeer Avatar answered Oct 03 '22 09:10

sadanand sudeer


Try the following directly inside the Ribbon Class:

RibbonDropDownItem item = this.Factory.CreateRibbonDropDownItem();
item.Label = "Text";
combo.Items.Add(item);
like image 40
Lee Avatar answered Oct 03 '22 09:10

Lee


jeds, your approach doesn't work with "new". You have to use the "Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem()". Otherwise, you are right and your approach works great with a RibbonGallery.

That approach also works great with a DropDown. I'm still often conflicted about which one to use...

However, other than those 2 objects (Dropdown and RibbonGallery), I believe drventure is correct. You simply have to stub out the objects ahead of time and use them as needed.

You can also use the XML Ribbon, but that creates an even bigger set of headaches (at least for my use cases).

like image 38
Brad Avatar answered Oct 03 '22 11:10

Brad