0

I have a customized Ribbon in Word. The Ribbon has one comboBox: comboBox_recentConditions which was defined using the Designer - so it's initalized and is empty at load. Now, I would like to dynamically set this comboBox each time the Application_WindowActivate event is fired.

Each Word document has its own instance of class called RibbonControls:

class RibbonControls
{
    private RibbonComboBox recentConditionComboBox;

    public RibbonControls()
    {
        this.recentConditionComboBox = new RibbonComboBox();
    }

    public RibbonComboBox RecentConditionComboBox
    {
        get
        {
            return recentConditionComboBox;
        }
        set
        {
            recentConditionComboBox = value;
        }
    }
}

Now in Application_WindowActivate event i do the following:

    static void Application_WindowActivate(Document doc, Window Wn)
    {
        Globals.Ribbons.SourceRibbon.comboBox_recentConditions = WordGate.docRibbonControls.RecentConditionComboBox; 
    }

The problem is that the Ribbon comboBox control doesn't changes, it's always empty, even after Application_WindowActivate is called. I tested at run-time to see if each document indeed has its own comboBox with its items - which seems to work. What am I missing?

To clear my question: Let's say I have 3 items in the comboBox.Items. When clicking on it I see nothing, but if I add this:

MessageBox.Show(Globals.Ribbons.SourceRibbon.comboBox_recentConditions.Items.Count.ToString());

at the end of Application_WindowActivate it will print the number 3.

Thanks.

etaiso
  • 2,736
  • 3
  • 26
  • 38

1 Answers1

0

You cant do it that way. Please have a read on Ribbon callbacks

You have to use the getItemLabel event which will add items to combo box. If you want to load the combobox during WindowActivate then call Ribbon.Invalidate or Ribbon.InvalidateControl which will call all relevant ribbon callbacks.

Kiru
  • 3,489
  • 1
  • 25
  • 46