How-To: Enable/Disable ribbon button

Discussions related to custom development with Select.
Post Reply
BobRichards
Posts: 982
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

How-To: Enable/Disable ribbon button

Post by BobRichards » Wed May 23, 2018 3:59 pm

You can initialize the ribbon button state to disabled adding "DefaultDisabled" to the style attribute of the Button element definition (in the CTD file).

Code: Select all

<Button id="RibbonButton1" kind="Button"   largeImage="Resources\Gear_32x32.png"
    smallImage="Resources\Gear_16x16.png" priority="10" text="Explode"
    style="TextUnderneath DefaultDisabled"
    toolTip="Click here to invoke RibbonButton1." />
To change the state, you will need to register the button handler. Include an event handler for the Query Status delegate.

Code: Select all

// RibbonButton1_Invoked called when button is pressed when enabled.
// RibbonButton1_QueryStatus is called when ribbon is about to display button and needs enable/disable state.
this.RegisterHandler(MyPackage.RibbonButton1, this.RibbonButton1_Invoked, this.RibbonButton1_QueryStatus);
When the ribbon control needs to display the button or a state change is detected, it will call your QueryStatus handler and you set the state.

Code: Select all

private void RibbonButton1_QueryStatus(object sender, QueryStatusEventArgs e)
{
    e.Enabled = (true/false)
}
Bob Richards, Software Developer, SoftPro

Post Reply