Tuesday, December 1, 2015

Conditionally hide Report Viewer buttons Ax2012

Today I was stuck in a situation where I had to disable the export button on the report viewer if the journal is not posted. After googling I got the below code which sits on the SRSReportViewer form:

private void hideExportButton()
{
    System.Windows.Controls.UIElementCollection elementLocal;
    Microsoft.Reporting.WinForms.ReportViewer   reportViewer;

    elementLocal = _AxReportViewer_Control.get_Children();
    reportViewer = elementLocal.get_Item(0);
    reportViewer.set_ShowExportButton(false);
}
Credit: http://www.agermark.com/2014/12/hide-export-button-from-report-viewer.html

You should have either different designs or menuItems for each condition to be called on the "init" method of the "SRSReportViewer" form. Add your custom code to call the hideExportButton where "_AxReportViewer_Control" is initialized.

// In case of multiple designs
    if(this.controller().parmReportName() like "*FundsTransferNoExport*")
    {
        this.hideExportButton();
    }
// In case of multiple menuitems
    if(this.args().menuItemName("*FundsTransfer*"))
    {
        this.hideExportButton();
    }

No comments:

Post a Comment