Search code examples
c#.netms-wordoffice-interopoffice-automation

Dynamically adding RibbonButtons in Word Addin throws Collection is readonly


I am fairly new to Word AddIns and trying to add Ribbon Group(s). for each RibbonGroup i dynamically add RibbonMenu and then add RibbonButtons to menu inside a Group.

I got the groud work and it seems to be okie but whenever i access any collection

eg: group1.Items.add(new RibbonButton()); it throws me saying that Collection is ReadOnly.

But When i debugged the Collection's IsReadOnly flag is set to False which clearly tells that Collection is not readonly?

What am i missing.


Solution

  • The Collection gets read-only once your Ribbon gets loaded.

    To modify the Ribbon control dynamically, you need to do it in the Ribbon constructor.

    See http://msdn.microsoft.com/en-us/library/bb608623.aspx#SettingReadOnlyProperties