none
Ribbon checkbox added to QAT from Outlook does not have same state. RRS feed

  • Question

  • Hi,

    In my Outlook Add-in there is a checkbox added to new email window (TabNewMailMessage).

    The XML is as below:

    <?xml version="1.0" encoding="UTF-8"?> <customUI xmlns = "http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load"> <ribbon> <tabs> <tab idMso="TabNewMailMessage">

    <group id="TestGRP" label="Test Group" getVisible="EnableGroup"> <checkBox id="CBID" label="TestCB" onAction="TestCB_Checked" getPressed ="get_TestCBPressed" /> </group> </tab> </tabs> </ribbon> </customUI>

    All works fine until the checkbox is clicked from Ribbon. I have a flag set (on checkbox state) based on which actions are performed while the email is sent.

    But when we add the checkbox to quick access toolbar (QAT) via Outlook (right click->Add to QAT), the behavior of the checkbox in  QAT is reversed.

    When we check the ribbon checkbox, the QAT checkbox becomes unchecked and vice versa. Similarly when the QAT checkbox is checked the ribbon checbox becomes unchecked.

    The OnAction() gets called on clicking either of the checkboxes. 

    Why the STATE of two chekboxes different?

    Thanks

    Thursday, November 22, 2012 1:01 PM

Answers

  • this code works perfectly for me:

    public void TestCB_Checked(Office.IRibbonControl control, ref bool pressed)
    {
      counter = pressed ? 0 : 1;
    }
            
    int counter = 0;
    public bool get_TestCBPressed(Office.IRibbonControl control)
    {
       return counter % 2 == 0;
    }

    please try it on your side
    • Marked as answer by ank_s Friday, November 30, 2012 10:20 AM
    Friday, November 23, 2012 12:46 PM

All replies

  • could you share your get_TestCBPressed function? we need to see loginc that determines what is returned from that function.
    Thursday, November 22, 2012 2:33 PM
  • The code for get_TestCBPressed () is below:

     public bool get_TestCBPressed(Office.IRibbonControl control)
            {
                bool bRetVal = false;
                try
                {
                    if (ThisAddIn.bOIPAvailable && control.Context is Outlook.Inspector)
                    {
                        bool bFound = false;
                        Outlook.Inspector oInsp = control.Context as Outlook.Inspector;
                        if (oInsp.CurrentItem is Outlook.MailItem)
                        {
                            Outlook.MailItem oMail = oInsp.CurrentItem as Outlook.MailItem;
                            if (oMail.Sent == false)
                            {
                                InspectorWrapper inspectorWrapper = null;
                                foreach (KeyValuePair<Guid, InspectorWrapper> wrapperPair in OIP.Globals.ThisAddIn._wrappedInspectors)
                                {
                                    if (oInsp == wrapperPair.Value.Inspector)
                                    {
                                        bFound = true;
                                        inspectorWrapper = wrapperPair.Value;
                                        var miwrapper = inspectorWrapper as MailItemWrapper;
    				    // flag to check if new email originated from within Application
                                        if (miwrapper.m_bOrigin)
                                        {
                                            bRetVal = true;
                                        }
                                    }
                                }
    
                                if (!bFound)
                                {
                                    OIP.Globals.ThisAddIn.WrapInspector(oInsp);
                                }
                            }
                        }
                    } 
                }           
                catch (Exception ex2)
                {
                    System.Diagnostics.Debug.WriteLine(ex2.Message);
                }
                return bRetVal;
            }


    Also I see that on openiong the new message window for the first time, the get_TestCBPressed() executes twice and the initial state of both the checkboxes is same (either checked or unchecked depending on from where the new email is getting created).

    But later on clicking on either checkbox, the procedure get_TestCBPressed() executes only once.

    Why is this so?

    • Edited by ank_s Friday, November 23, 2012 10:04 AM Modifications
    Friday, November 23, 2012 9:58 AM
  • try at the end of TestCB_Checked calling ribbon.InvalidateControl("CBID");
    Friday, November 23, 2012 10:53 AM
  • On adding ribbon.InvalidateControl("CBID"), it keeping calling get_TestCBPressed() again and again. Also the state is not getting changed.
    Friday, November 23, 2012 11:27 AM
  • this code works perfectly for me:

    public void TestCB_Checked(Office.IRibbonControl control, ref bool pressed)
    {
      counter = pressed ? 0 : 1;
    }
            
    int counter = 0;
    public bool get_TestCBPressed(Office.IRibbonControl control)
    {
       return counter % 2 == 0;
    }

    please try it on your side
    • Marked as answer by ank_s Friday, November 30, 2012 10:20 AM
    Friday, November 23, 2012 12:46 PM
  • Thanks Damian, it works. But the initial state is checked for checkbox.

    I need the default state needs to be unchecked.

    Friday, November 23, 2012 1:44 PM
  • then change inital value of counter to 1. Anyway, it is just to show you that error is inside your logic for returning state, since it works with such simple code quite well.
    Friday, November 23, 2012 2:40 PM