none
click event for check-box/toggle button firing automatically in Excel add-in project RRS feed

  • Question

  • I just created a test excel-addin project with only one control (toggle button). I set the publish option to Load On Demand (as shown in the screenshot below). The checked property for the toggle button is set to True in the designer. If I now build this and open excel, close and reopen excel, the click event is auto-fired. 

    On the other hand, if chose Load at startup option, this does not happen.

    Any suggestions how to stop the auto-click event or any work around

    because I need to set the checked property of the togglebutton on ribbon_load but cannot do so without click event getting fired automatically.

    Here is my code:

    namespace ExcelAddIn1
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {                   
            }
             private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
            {
                toggleButton1.Label = "inside";
            }
        }

    Wednesday, October 15, 2014 3:51 AM

Answers

All replies

  • Hello Chaitak,

    It looks like the problem is not in the Click event. The Ribbon UI is a static thing from its birth. You need to use callbacks, not to set values in the Load event like you did for any UI controls in .Net applications.

    There is no need to handle the Click event of the toggleButton control for changing the label property. Instead, you need to use the callback. For example, to change the label you need to declare the getLabel attribute. And when you need to update/refresh values you can call the Invalidate method of the IRibbonUI interface. It invalidates the cached values for all of the controls of the Ribbon user interface, your callbacks are invoked to get new values.

    You can read more about the Ribbon UI (Fluent UI) in the following series of articles in MSDN:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    Wednesday, October 15, 2014 3:33 PM
  • Hi Eugene,

    I think the question was about the issue that the button click is getting triggered automatic:

    " If I now build this and open excel, close and reopen excel, the click event is auto-fired" 

    I have same situation but i have Ribbon.xml. For me, I have a toggle button and have a method for onAction.

    The method is getting called automatic. Other validation methods like getEnabled, getImage ...get*** etc is correct, but why should my onAction event be called ?

    I guess its based on the response to getPressed callback for the togglebutton. But thats completely incorrect as it seems on second load, apart from restoring the ribbon buttons state, its trying to execute the action.

    Am not able to unmark your comment as answer!!

    Wednesday, March 4, 2015 7:39 AM