1592578 - How to disable/hide individual buttons in the Crystal Reports .NET Windows Form viewer

SAP Knowledge Base Article - Public

1592578 - How to disable/hide individual buttons in the Crystal Reports .NET Windows Form viewer

Symptom

  • Developing a .NET Windows application using the Crystal Reports .NET SDK and the CrystalReportViewer control.
  • How to disable, or hide, individual buttons in the toolbar?
    • Eg. How to disable ONLY the "Go to Last Page" button.

Default buttons

lastpagebuttonPresent.png

Removed the Go to Last Page button

lastpagebuttonRemoved.png

Environment

  • Visual Studio 2008 or 2005
  • Crystal Reports 2008 SP3

Resolution

  • The fourth control in the CrystalReportViewer contains a ToolStrip of items which can be modified.
  • Each individual control can be made invisible so the user can't interact with it.
  • Please note, you should use the appropriate Show*Button property whenever possible. Only use this method if the various Show*Button properties don't suit your needs.
    • ShowCloseButton
    • ShowCopyButton
    • ShowExportButton
    • ShowGotoPageButton
    • ShowGroupTreeButton
    • ShowPageNavigationButtons
    • ShowParameterPanelButton
    • ShowPrintButton
    • ShowRefreshButton
    • ShowTextSearchButton
    • ShowZoomButton
private void DisableToolStripItems(CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1)
{           
 try
 {
  
  System.Windows.Forms.ToolStrip oToolStrip = (System.Windows.Forms.ToolStrip)crystalReportViewer1.Controls[3];
  foreach (System.Windows.Forms.ToolStripItem oToolStripItem in oToolStrip.Items)
  {
   switch (oToolStripItem.AccessibleName)
   {
    case "Go to Last Page":
    case "Add more items here to disable them":
     oToolStripItem.Visible = false;
     break;
    default:
     break;
   }   
   /* Other available items on the toolstrip to disable
    Export Report
    Print Report
    Refresh
    Copy
    Toggle Parameter Panel
    Toggle Group Tree
    Go to First Page
    Go to Previous Page
    Go to Next Page
    Go to Last Page
    Go to Page
    Find Text
    Zoom
    Close Current View
    * */
  }               
  
 }
 catch (Exception ex)
 {
  // Do something with exception ex.
  string message = ex.Message;
 }           
}

 

Keywords

KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

Crystal Reports 2008 V1