none
How to access checkbox on ribbon on mailitem RRS feed

  • Question

  • I have created a ribbon add-on that contains a checkbox. The ribbon add-on is attached to each mailitem.

    Since you can open two mail items, it is possible that on one mailitem the ribbon checkbox will be checked, and on the other it will be unchecked.    I am hooking (handing) mailitem.send to perform actions dependent on whether the mailitem's ribbon checkbox is checked or not. 

    What is the correct mechanism to specify the correct ribbon checkbox (ie the one associated with the mailitem being sent).

    Visual studio 2012, Office 15



    Friday, September 13, 2013 8:30 PM

Answers

  • Usually we maintain collections of wrapper classes where we want to track multiple instances of objects such as Inspectors (or items). Each wrapper class would reference the Inspector, MailItem, flag value for the state of the checkbox, and other relevant variables.

    When you get a callback on the ribbon control you get a control reference passed to you. Use control.Context to get the Inspector where the click occurred on the ribbon control. Compare the Inspector in each wrapper class to the control.Context cast as an Inspector. If they're the same you have the wrapper class. Set or clear the flag for checkbox state as a toggle on the existing state.

    For events on the Inspector or item, handle them in the wrapper class. The event handler in the correct wrapper class will be called when an event such as Send() fires.


    Ken Slovak MVP - Outlook

    Tuesday, September 17, 2013 8:47 PM
    Moderator

All replies

  • Hi,

    What do you mean by “The ribbon add-on is attached to each mailitem”? Is it means that RibbonType property in the .Designer.cs file of the ribbon is “Microsoft.Outlook.Mail.Read”? Or “Microsoft.Outlook.Explorer”?

    According to your description, I think you want to make the “mailitem.send” operate relate to the checked property of the checkbox. But I'm not sure about how do you want to relate the event to the checkbox.

    Could you descripte your requirement more detailed.

    Here is a sample to override the send event for your referrence.

    Please include this line in your Add-in_StartUp:

    Globals.ThisAddIn.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(ThisAddIn_Send);

    The implementation of the event handler:

    void ThisAddIn_Send(object Item, ref bool Cancel)
    {
        if (checkBox1.Checked == true)
        {
            //MessageBox.Show("MailItem is Sent");
            Cancel = false;
        }
        else
        {
            Cancel = true;
        }
    }
    Monday, September 16, 2013 2:07 PM
  • I am using VB.

    RibbonType = "Microsoft.Outlook.Mail.Compose, Microsoft.Outlook.Mail.Read"

    My code was already hooking the Send event by adding

    AddHandler addon_outlook.ThisAddIn.olApp.ItemSend, AddressOf olApp_HookItemSend

    Within my olApp_HookItemSend I have similar syntax
       If (CheckBox_SendModified.Checked) Then

    My problem is that if I have two mail items open, then there are two ribbon contexts.. 
    I could check or uncheck either one..   So the olApp_HookItemSend responds to the last check, not the current check per MailItem

    I want to be able to determine the state of the Checkbox associated with the ribbon that is associated with the mailitem..  I can get a reference to the MailItem by using  an Inspector, but have not figured out how to reference the 1 of N ribbons attached to N MailItems


    • Edited by MattMo[XBOX] Tuesday, September 17, 2013 8:02 PM
    Tuesday, September 17, 2013 8:00 PM
  • Usually we maintain collections of wrapper classes where we want to track multiple instances of objects such as Inspectors (or items). Each wrapper class would reference the Inspector, MailItem, flag value for the state of the checkbox, and other relevant variables.

    When you get a callback on the ribbon control you get a control reference passed to you. Use control.Context to get the Inspector where the click occurred on the ribbon control. Compare the Inspector in each wrapper class to the control.Context cast as an Inspector. If they're the same you have the wrapper class. Set or clear the flag for checkbox state as a toggle on the existing state.

    For events on the Inspector or item, handle them in the wrapper class. The event handler in the correct wrapper class will be called when an event such as Send() fires.


    Ken Slovak MVP - Outlook

    Tuesday, September 17, 2013 8:47 PM
    Moderator
  • Thanks Ken,

    It sounds like you know what I should be doing, but my understanding is still not there

    Could you give example of how you would track multiple instances of objects by maintaining collections of wrappers classes ?

    Thanks Matthew

    Tuesday, September 17, 2013 10:42 PM
  • They're a bit out of date, but the principle is still valid, see the templates at http://www.slovaktech.com/outlook_2007_templates.htm. They're for Outlook 2007 with VS 2005, but they will illustrate the concept and can be imported into later versions of VS.

    Ken Slovak MVP - Outlook

    Wednesday, September 18, 2013 2:49 PM
    Moderator