none
Using ribbon xml how to I uncheck a checkbox after the user clicks the checkbox and hits send RRS feed

  • Question

  • Using ribbon xml how to I uncheck a checkbox after the user clicks the checkbox and hits send? 

    Here's what I'm attempting to do. Any help would be greatly appreciated been trying to figure this out all day.

    My ribbon.xml looks like this-(loads ribbon on new message)

    <?xml version="1.0" encoding="UTF-8"?>

    <customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
      <ribbon>
        <tabs>
          <tab idMso="TabNewMailMessage">
            <group id="group1" label="test" autoScale="true" getImage="GetCustomImage" centerVertically="true">


    <checkBox id="SecureCheckBox" onAction="SecureOnActionCallback" getPressed="chkTest_pressed" />

              </dialogBoxLauncher>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>


    and this is my ribbon.cs-

    //this OnAction call back used on the Send Secure Email button
            public void SecureOnActionCallback(Office.IRibbonControl control, bool isPressed)
            {
    
                if (control.Id == "SecureCheckBox")
                {
                    var addin = Globals.ThisAddIn;
    
                    if (checkClickSecure == 0)
                    {
                        addin.AddSecure();
                        checkClickSecure = 1;
                    }
                    else
                    {
                        addin.RemoveSecure();
                        checkClickSecure = 0;
                    }
                    
                }
                //I can invalidate the checkbox here but I need to do this in the ThisAddin.cs one the Item is sent
    			//ribbon.InvalidateControl(control.Id);
                
            }
    

    I've been playing around with this in my ribbon.cs but getting nowhere-

            private bool isChecked = false;
    
            public bool chkTest_pressed(IRibbonControl ribbon) 
            {
                MessageBox.Show("I get to chkTest_pressed");
                this.ribbon.Invalidate();
                return isChecked;
                //isChecked = true;
                //ribbon.Invalidate();
                //ribbon.InvalidateControl(control.Id);
    
                //this.ribbon.InvalidateControl("SecureCheckBox");
                
            }

    Finally what I want to do is reset the checkbox once my code runs from the ThisAddin.cs but I can't seem to get my head around how. 

    Here's the code from ThisAddin.cs-

    
    
    //adds secure tag in subject line. the "Send Internet Encrypted Email" button calls this function.
            public void AddSecure()
            {
                //calls the function "addSecureTag" when the send button is pressed. 
                this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(addSecureTag);
                //Can't get this to work
                //ribbon.InvalidateControl(control.Id);
            }
    
    
            //unloads the function "addSecureTag" when the "Send Internet Encrypted Email" button is unchecked. 
            public void RemoveSecure()
            {
    
                this.Application.ItemSend -= new Outlook.ApplicationEvents_11_ItemSendEventHandler(addSecureTag);
    
            }

    • Moved by Amanda Zhu Thursday, September 25, 2014 2:14 AM
    Wednesday, September 24, 2014 2:59 AM

Answers

  • Hi Kevin,

    To invalidate the controls if Ribbon if we are using Ribbon (XML) project, we could use IRibbonUI.InvalidateControl method.

    Based on your code, please follow up these steps below:

    1. Open Ribbon class (E.g. Ribbon1)
    2. Modify this code below. (Change private to internal)
    internal Office.IRibbonUI ribbon;  
    1. Open ThisAddIn.cs
    2. Define a variable
    private Ribbon1 ribbin;

    1. In the CreateRibbonExtensibilityObject override method, the code will be like this:
     protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                ribbin = new Ribbon1();
                return ribbin;
       
            }

    1. In the addSecureTag, call InvalidateControl method.
     ribbin.ribbon.InvalidateControl("SecureCheckBox");

    Note: That is the sample to tell you how to invalidate the control. You need base on your requirement to modify the code. (E.g. checkClickSecure variable is not reset, so the for the first email it Ribbon control is invalidate, for the second email that control not invalidate, because the value of checkClickSecure is 1, it will remove the event addin.RemoveSecure())

    There is a good article about custom Ribbon that may benefit you:

    # Customizing the Ribbon in Outlook 2007

    http://msdn.microsoft.com/en-us/library/bb226712.aspx

    Best Regards

    Starain Chen


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Sunday, September 28, 2014 2:15 AM
    Moderator

All replies

  • Have you verified if there is a Globals.Ribbons. For example, check if Globals.Ribbons.First() is convertible to your ribbon class. According to articles, seems easier to access the ribbon using an expression like ‘Globals.Ribbons.Ribbon1’ if you use Ribbon Designer instead of Ribbon XML.

    Wednesday, September 24, 2014 6:18 AM
  • Hi Viorel, I agree Ribbon Designer is so much easier to use unfortunately that caused this issue where Excel has a ghosted window- Link so Microsoft support recommended to use XML ribbons instead. This fixes the Excel issue but complicates everything. 

    Can you access the XML ribbon using Globals.Ribbon or is that just when using the Ribbon Designer?

    I think this is what you're talking about - Link

    The reason I ask is intellisense does not seem to give me an option for any ribbon specifically-

    Wednesday, September 24, 2014 3:52 PM
  • Hi Kevin,

    Your  issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System and Visual Studio Editor.

    Visual Studio Tools for Office (VSTO)  is a better forum for your issue, I moved this thread there, you will get better support and solution there.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 25, 2014 2:17 AM
  • OK, thanks. Sorry for the confusion.After reading this thread, link, it seems that I can't use the Globals.Ribbon as you can when using the a Ribbon (XML) project.

    I think what I need to do is invalidate the ribbon to clear the checkbox after I send the email. 

    I just can't figure out how to do that from ThisAddinIN.cs after I send the email using this line- 

    this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(addSecureTag);

    Thursday, September 25, 2014 1:55 PM
  • Hi Kevin,

    To invalidate the controls if Ribbon if we are using Ribbon (XML) project, we could use IRibbonUI.InvalidateControl method.

    Based on your code, please follow up these steps below:

    1. Open Ribbon class (E.g. Ribbon1)
    2. Modify this code below. (Change private to internal)
    internal Office.IRibbonUI ribbon;  
    1. Open ThisAddIn.cs
    2. Define a variable
    private Ribbon1 ribbin;

    1. In the CreateRibbonExtensibilityObject override method, the code will be like this:
     protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                ribbin = new Ribbon1();
                return ribbin;
       
            }

    1. In the addSecureTag, call InvalidateControl method.
     ribbin.ribbon.InvalidateControl("SecureCheckBox");

    Note: That is the sample to tell you how to invalidate the control. You need base on your requirement to modify the code. (E.g. checkClickSecure variable is not reset, so the for the first email it Ribbon control is invalidate, for the second email that control not invalidate, because the value of checkClickSecure is 1, it will remove the event addin.RemoveSecure())

    There is a good article about custom Ribbon that may benefit you:

    # Customizing the Ribbon in Outlook 2007

    http://msdn.microsoft.com/en-us/library/bb226712.aspx

    Best Regards

    Starain Chen


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Sunday, September 28, 2014 2:15 AM
    Moderator