SAP Knowledge Base Article - Public

1532955 - CRVS2010 - How to hide the Side Panel when using the WPF viewer?

Symptom

  • Windows Forms Viewer SDK for VS .NET has a property called "ToolPanelView" which allows hiding of the SidePanel
  • The WPF viewer does not have such a property exposed

Resolution

  • Use the following code to show the report
Thread thread = new Thread(HideSideBarThread);
thread.Start();
 
CrystalReportsViewer reportViewer = GetReportViewer();
reportViewer.ViewerCore.ReportSource = report;
  • Then use the following support functions
private delegate bool HideCrystalReportsSideBarDelegate();
 
private void HideSideBarThread()
{
    bool isVisible = true;
    int timeOut = 60000;
    int currentTime = 0;
 
    while (isVisible && currentTime < timeOut && !this.Dispatcher.HasShutdownStarted)
    {
        isVisible = (bool)this.Dispatcher.Invoke(new HideCrystalReportsSideBarDelegate(HideCrystalReportsSideBar), null);
        Thread.Sleep(100);
        currentTime += 100;
    }
 
}
 
private bool HideCrystalReportsSideBar()
{
    bool isVisible = true;  // assume that the default SideBar status is visible         
 
    CrystalReportsViewer reportViewer = GetReportViewer();
    if (reportViewer != null)
    {
        ReportAlbum reportAlbum = (ReportAlbum)reportViewer.ViewerCore.FindName("reportAlbum");
        if (reportAlbum != null)
        {
            TabControl tabViews = (TabControl)reportAlbum.FindName("tabViews");
            if (tabViews != null && tabViews.Items.Count > 0)
            {
                DocumentView doc = (DocumentView)tabViews.Items[0];
                Grid grid = (Grid)doc.FindName("grid");
                if (grid != null)
                {
                    GridLength gridLength = new GridLength( 0, GridUnitType.Pixel);
                    if (gridLength != grid.ColumnDefinitions[0].Width) // required on report refresh to wait for the new report
                    {
                        grid.ColumnDefinitions[0].Width = gridLength;
                        isVisible = false;
                    }
                }
            }
        }
    }
    return isVisible;
}
 
private CrystalReportsViewer GetReportViewer()
{
    CrystalReportsViewer reportViewer = null;
 
    // TODO: implement to return your CrystalReportsViewer
   ...
 
    return reportViewer;
}

Keywords

cr4vs2010 2010 vs2010 crforvs 13 WPF Windows Presentation Foundation , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio