4

I'm adding items to a RibbonDropDown that is used by the New Email inspector at run time. I add the items on start-up and also refresh the list on demand (when the user presses a button)

public void RefreshListNames()
{
    Logger.Log("Refresh Mail Lists");

    Globals.Ribbons.Ribbon1.rddListNames.Items.Clear();
    foreach (KeyValuePair<Guid, string> kvp in _dda.GetMarketingListNames())
    {
        Microsoft.Office.Tools.Ribbon.RibbonDropDownItem dd = 
            Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();

        dd.Tag = kvp.Key;
        dd.Label = kvp.Value;

        Logger.Log("Adding " + dd.Label);

        Globals.Ribbons.Ribbon1.rddListNames.Items.Add(dd);

    }

    Globals.Ribbons.Ribbon1.rddListNames.ResumeLayout();
}

Note: rddListNames is a RibbonDropDown

This method is called in the ThisAddIn_Startup method and populated corectly on start-up. However, any new Mail window ends up with a blank dropdown - no items. Even refreshing the list doesn't add the items back again.

I added some logging: it shows that the method is running when the 'refresh button' is pressed:

23/04/2013 14:36:43 - Refresh Mail Lists 
23/04/2013 14:36:45 - Adding Marketing List - Dynamic 
23/04/2013 14:36:45 - Adding Marketing List - Bs 
23/04/2013 14:36:45 - Adding Marketing List - As

Why does the drop down keep loosing items? And why don't they come back, even if I explicitly refresh them?

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Ryan
  • 3,924
  • 6
  • 46
  • 69
  • I also tried Globals.Ribbons.Ribbon1.rddListNames.ResumeLayout(); - though since I am not explicitly suspending layout, unsurprisingly, this didn't make any difference. – Ryan Apr 23 '13 at 07:04
  • Are you using the [**Ribbon XML** or **Ribbon Designer**](http://stackoverflow.com/a/9379747/175679)? – SliverNinja - MSFT Apr 29 '13 at 14:22
  • I was using the designer - but can export the designed ribbon to xml for hand editing if needed. – Ryan Apr 30 '13 at 00:02

1 Answers1

1

If you make control modifications to the Ribbon UI, you need to invalidate the control cache via IRibbonControl.Invalidate() or IRibbonControl.InvalidateControl. This will trigger a repaint of the Ribbon elements.

Globals.Ribbons.Ribbon1.Invalidate();
// or...
Globals.Ribbons.Ribbon1.InvalidateControl("ddMarketingList");
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • I have tried this - added after the loop that clears/re-instates the dropdown items. However, it still doesn't work - still blank. Is there a specific way to call this? (I can't find an example of doing it any other way). Thanks – Ryan Apr 24 '13 at 02:49
  • I have also tried Globals.Ribbons.Ribbon1.rddListNames.PerformDynamicLayout(); and dd.Parent.PerformDynamicLayout(); – Ryan Apr 29 '13 at 02:47