none
Reset ribbon togglebutton on all open Outlook mailitems RRS feed

  • Question

  • I have a VSTO Outlook addin, with a designer ribbon that has a togglebutton and a menu button.  This new ribbon appears for New or Reply messages.  When the user changes their preferences, via the menu button, which in turn opens a Windows Form, I set the togglebutton according to their selected preference.  This is easy for the current active Outlook mailitem, however, I need to set the togglebutton on all open Outlook mailitems.  

    (Visual Studio 2008 VSTO Outlook 2007) 

    Tuesday, November 22, 2011 2:25 AM

Answers

  • The sample code will only access the ActiveInspector() object. To extend it to all Inspectors it has to be modified, something like this:
     
    Private void Access_Ribbons_By_Inspector()
    {
        Outlook.Inspectors insps = Globals.ThisAddIn.Application.Inspectors;
        int count = insps.Count;
        if (count > 0)
        {
            ThisRibbonCollection ribbonCollection = null;
            Outlook.Inspector insp = null;
     
            for (int i = 1: i <= count; i++)
            {
                insp = insps[i];
                ribbonCollection = Globals.Ribbons [insp];
     
                ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";
            }
        }
    }
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "J Wagner" <=?utf-8?B?SiBXYWduZXI=?=> wrote in message news:8edd51a2-c99a-4c1f-8b72-f8f947b85933...
    Well, I had tested that code and it only picks up the current ActiveInspector, not all other open windows.
    How do you iterate the ribbonCollection?  maybe the 2nd statement only sets the 1st inspector?

    Ken Slovak MVP - Outlook
    • Marked as answer by J Wagner Wednesday, November 23, 2011 6:42 PM
    Wednesday, November 23, 2011 5:56 PM

All replies

  • If you call Ribbon.Invalidate() that should invalidate the ribbon for every open item. When your callbacks are called for each item you will get a control object passed in the callback, the Context property of the control object is the relevant Inspector or Explorer for that ribbon control.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "J Wagner" <=?utf-8?B?SiBXYWduZXI=?=> wrote in message news:07d61288-ae1e-4693-857c-e9753011d025...

    I have a VSTO Outlook addin, with a designer ribbon that has a togglebutton and a menu button.  This new ribbon appears for New or Reply messages.  When the user changes their preferences, via the menu button, which in turn opens a Windows Form, I set the togglebutton according to their selected preference.  This is easy for the current active Outlook mailitem, however, I need to set the togglebutton on all open Outlook mailitems.  

    (Visual Studio 2008 VSTO Outlook 2007) 


    Ken Slovak MVP - Outlook
    Tuesday, November 22, 2011 2:18 PM
  • I'm using ribbon designer, does that make a difference?    Can I not just use 'globals.ribbons' for the open items? 
    Tuesday, November 22, 2011 5:52 PM
  • That should work.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "J Wagner" <=?utf-8?B?SiBXYWduZXI=?=> wrote in message news:da4847a3-4c6c-4122-bc34-5c792384a966...
    I'm using ribbon designer, does that make a difference?    Can I not just use 'globals.ribbons' for the open items? 

    Ken Slovak MVP - Outlook
    Tuesday, November 22, 2011 11:17 PM
  • Well I tried various combinations, seems to work the first time, but if I set the button again with the same windows open, it only updates the current active window.

    Globals.Ribbons.myRibbon.ToggleButton1.Checked = gToggle
    ToggleButton1.Checked = gToggle
    

    Am I missing something?

    Wednesday, November 23, 2011 3:16 AM
  • Hi J,

    Would you like to share more code with us. It is difficult for me to find the solution without little part of code.

    Wednesday, November 23, 2011 12:50 PM
  • I'm not sure with the ribbon designer, I rarely use it (I usually use ribbon XML instead for complete control over everything).
     
    This code is shown for accessing a specific Inspector's ribbon in the article at http://msdn.microsoft.com/en-us/library/bb772088.aspx#Y536, does the code or the article help?
     

    private void Access_Ribbons_By_Inspector()

    {

        ThisRibbonCollection ribbonCollection = Globals.Ribbons [Globals.ThisAddIn.Application.ActiveInspector()];

        ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";

    }


    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "J Wagner" <=?utf-8?B?SiBXYWduZXI=?=> wrote in message news:85fee142-7cce-4ee8-8e3b-9cf173987fd1...

    Well I tried various combinations, seems to work the first time, but if I set the button again with the same windows open, it only updates the current active window.

    Globals.Ribbons.myRibbon.ToggleButton1.Checked = gToggle
    ToggleButton1.Checked = gToggle
    

    Am I missing something?


    Ken Slovak MVP - Outlook
    Wednesday, November 23, 2011 3:11 PM
  • Ken, I had checked out that site, but the code with the collection is the same as saying

    me.ToggleButton1.checked = gToggle.

    Expanding on the more code request:

    myRibbon.vb has a new tab with 1 button and a menu dropdown with buttons (dynamic).  One of the dropdown buttons is btnPreferences.  Let me know if more code is required.  Thanks.

    Public Class myRibbon
    
        Private Sub myRibbon_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
            Call Menu1_Populate()
            ToggleButton1.Checked = gToggle
        End Sub
    
        Private Sub btnPreferences_Click(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles btnPreferences.Click
            Dim frm As New frmSettings
            frm.ShowDialog()
            Globals.Ribbons.myRibbon.ToggleButton1.Checked = gToggle
        End Sub
    
    End Class
    


     

    Wednesday, November 23, 2011 4:33 PM
  • I don't think that sample code is the same at all, as it instantiates the ribbons collection for the ActiveInspector() object.
     
    Getting the Inspectors collection and iterating it and instantiating a new ThisRibbonCollection object for each Inspector should allow you to set the toggle button for each Inspector as far as I know.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "J Wagner" <=?utf-8?B?SiBXYWduZXI=?=> wrote in message news:f5334d02-2a35-4f50-b3fd-4fe428d9643b...

    Ken, I had checked out that site, but the code with the collection is the same as saying

    me.ToggleButton1.checked = gToggle.

    Expanding on the more code request:

    myRibbon.vb has a new tab with 1 button and a menu dropdown with buttons (dynamic).  One of the dropdown buttons is btnPreferences.  Let me know if more code is required.  Thanks.

    Public Class myRibbon
    
        Private Sub myRibbon_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load
            Call Menu1_Populate()
            ToggleButton1.Checked = gToggle
        End Sub
    
        Private Sub btnPreferences_Click(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles btnPreferences.Click
            Dim frm As New frmSettings
            frm.ShowDialog()
            Globals.Ribbons.myRibbon.ToggleButton1.Checked = gToggle
        End Sub
    
    End Class
    


     


    Ken Slovak MVP - Outlook
    Wednesday, November 23, 2011 4:42 PM
  • Well, I had tested that code and it only picks up the current ActiveInspector, not all other open windows.
    How do you iterate the ribbonCollection?  maybe the 2nd statement only sets the 1st inspector?
    • Edited by J Wagner Wednesday, November 23, 2011 5:27 PM
    Wednesday, November 23, 2011 5:25 PM
  • The sample code will only access the ActiveInspector() object. To extend it to all Inspectors it has to be modified, something like this:
     
    Private void Access_Ribbons_By_Inspector()
    {
        Outlook.Inspectors insps = Globals.ThisAddIn.Application.Inspectors;
        int count = insps.Count;
        if (count > 0)
        {
            ThisRibbonCollection ribbonCollection = null;
            Outlook.Inspector insp = null;
     
            for (int i = 1: i <= count; i++)
            {
                insp = insps[i];
                ribbonCollection = Globals.Ribbons [insp];
     
                ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";
            }
        }
    }
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "J Wagner" <=?utf-8?B?SiBXYWduZXI=?=> wrote in message news:8edd51a2-c99a-4c1f-8b72-f8f947b85933...
    Well, I had tested that code and it only picks up the current ActiveInspector, not all other open windows.
    How do you iterate the ribbonCollection?  maybe the 2nd statement only sets the 1st inspector?

    Ken Slovak MVP - Outlook
    • Marked as answer by J Wagner Wednesday, November 23, 2011 6:42 PM
    Wednesday, November 23, 2011 5:56 PM
  • Works!  Thanks Ken. 
    Wednesday, November 23, 2011 6:41 PM