none
Dynamically set RibbonControl

    Question

  • I have a customized Ribbon in Word. The Ribbon has one comboBox: comboBox_recentConditions which was defined using the Designer - so it's initialized and contains no items at load. Now, I would like to dynamically set this WHOLE 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.

    Sunday, October 06, 2013 12:35 PM

Answers

  • I'm having difficulty reconciling the RibbonControls class with the class created by VSTO - Globals.Ribbons.SourceRibbon. Without understanding how these two things (are supposed to) work together, it's not possible to consider what may be going wrong with your code.

    I'm not sure whether the following observations will help, but they're what comes to mind when reading your problem description:

    Ribbons in different documents (or add-ins) cannot interact with each other, unless they share a namespace. But you cannot do namespace sharing with a Ribbon created using the Designer, only with RIbbon XML.

    Any Ribbon linked specifically to a document is only visible to that document and not to any other.

     

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 08, 2013 4:23 PM
    Moderator

All replies

  • Please provide more information about what WordGate.docRibbonControls is.

    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, October 06, 2013 5:44 PM
    Moderator
  • It's just a reference to an instance of RibbonControls class, so it's actually returns the ComboBox control itself.

    I tought I should call invalidate or invalidateControl, but not sure where from (I tried from RibbonUI but didn't work).

    I will explain my goal here in short.

    For each document there are different Items in this ComboBox, so whenever user switch between documents, I want the comboBox Items to be changed. So I think (let me know if I'm wrong here) if everytime I re-populate the items (Clear(), then loop over some container to read data from) it will affect performance. 

    My idea is to store for each document a different ComboBox control so I don't have to clear it each time. Is that a good idea? if possible at all.

    Thanks.


    • Edited by etaiso Monday, October 07, 2013 6:13 AM
    Monday, October 07, 2013 6:08 AM
  • I'm having difficulty reconciling the RibbonControls class with the class created by VSTO - Globals.Ribbons.SourceRibbon. Without understanding how these two things (are supposed to) work together, it's not possible to consider what may be going wrong with your code.

    I'm not sure whether the following observations will help, but they're what comes to mind when reading your problem description:

    Ribbons in different documents (or add-ins) cannot interact with each other, unless they share a namespace. But you cannot do namespace sharing with a Ribbon created using the Designer, only with RIbbon XML.

    Any Ribbon linked specifically to a document is only visible to that document and not to any other.

     

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 08, 2013 4:23 PM
    Moderator