The user can choose to display a toolbar and menu or a Microsoft Office-like ribbon at the top of the Reports Explorer. If desired, you can customize the ribbon in an Application.ReportsExplorerReady script.

Check the RibbonVisible property of the Application object and only execute code customizing the ribbon if it's True. See the example code below.

The ribbon is referenced with an object named Ribbon. The tabs in the ribbon are named with the caption followed by "Tab" and are members of the Ribbon object; for example, the Home tab can accessed with Ribbon.HomeTab. Before customizing the ribbon, make sure it's displayed by ensuring the application object's RibbonVisible property is true.

When a tab is selected, a toolbar for that tab appears. A toolbar consists of sections and within each section are buttons. Sections are named with the caption followed by "Section" and are members of the Toolbar member of the tab object; for example, the Report section of the Home tab can be accessed with Ribbon.HomeTab.Toolbar.ReportSection.

Sections

To add a section to a tab, call the AddSection method of the tab, passing the name to use for the new section. That method returns a section object. Set the Caption property of the section object to the desired text.

Buttons

There are two types of buttons in the ribbon: regular and horizontal. In addition, a button can have a dropdown menu; if it does, a small down arrow appears in the button caption.

Buttons are named with the caption followed by "Button" and are members of the section object; for example, the Delete button in the Report section of the Home tab can be accessed with Ribbon.HomeTab.Toolbar.ReportSection.DeleteButton.

To add a button to a section, call either AddButton to add a regular button or AddHorizontalButton to add a horizontal button. Regular buttons are automatically added at the right end of the section and horizontal buttons are either added below the last horizontal button if there's at least one at the right end of the section and there's room below it or at the right end of the section if not. For example, in the image above, if the Sample Reports button wasn't there, AddHorizontalButton would add a button below Export. Since it is there and there isn't room below Sample Reports, AddHorizontalButton adds a button at the right end of the section.

AddButton and AddHorizontalButton return a button object. Set the Caption property of the object to the text for the button; to use a multi-line caption, include a carriage return (character 13) in the text or set the WordWrap property to true. Set the Image property to the image for the button: 32 x 32 for a regular button or 16 x 16 for a horizontal button. Set the Command property to the command to execute; it can consist of multiple statements separated by carriage returns. The EnabledExpression property optionally contains an expression (as a string) that evaluates to determine if the button is enabled.

The button has a dropdown menu if it has any bars in the menu. To add a bar to the menu, call the AddBar method of the button, passing the caption for the bar, the command to execute, optionally an image for the bar (16 x 16), and optionally an expression that determines when the bar is enabled (if it isn't passed, the bar is always enabled). To add a separator bar, pass no parameters to AddBar.

To hide a button, set its Visible property to true.

Here is an example that adds two buttons, one of which has a dropdown menu, to a Test section of the Home tab and hides the Delete button:

lparameters toApplication as SQApplication
if toApplication.RibbonVisible
    loSection = Ribbon.HomeTab.AddSection('TestSection')
    with loSection
        .Caption = 'Test'
        loButton = .AddButton('TestButton')
        with loButton
            .Caption = 'Test Button'
            .Image   = 'image1.png'
            .Command = "messagebox('Hello')"
        endwith

        loButton = .AddButton('MenuButton')
        with loButton
            .Caption = 'Menu' + chr(13) + 'Button'
            .Image   = 'image2.png'
            .AddBar('Menu item 1', "messagebox('Menu item #1')")
            .AddBar('Menu item 2', "messagebox('Menu item #2')")
            .AddBar()
            .AddBar('Menu item 3', "messagebox('Menu item #3')")
        endwith
    endwith

    Ribbon.HomeTab.Toolbar.ReportSection.DeleteButton.Visible = .F.
endif

Here is the result. Notice the new Test section at the right and the missing Delete button beside Edit.


© Stonefield Software Inc., 2023 • Updated: 04/14/21
Comment or report problem with topic