SAP Knowledge Base Article - Public

1288585 - How to modify a subreport using the Crystal Reports .NET SDK

Symptom

How to modify a subreport using the Crystal Reports .NET SDK?

Reproducing the Issue

  • .NET Visual Studio 2005
  • C#
  • Resolution

    sample code:

             using CrystalDecisions.CrystalReports.Engine;
             using CrystalDecisions.Shared;

            ReportDocument                m_boReportDocument;
            Sections                              m_boSections;
            ReportObjects                    m_boReportObjects;
            SubreportObject                 m_boSubreportObject;

            //create a new ReportDocument
             m_boReportDocument = new ReportDocument();

            //load the RPT file 
            m_boReportDocument.Load("..\\..\\HasSubreport.rpt");

             //get all the sections in the report
             m_boSections = m_boReportDocument.ReportDefinition.Sections;

             //loop through each section of the report
             foreach (Section m_boSection in m_boSections)
                {
                    m_boReportObjects = m_boSection.ReportObjects;

                    //loop through each report object
                    foreach ( ReportObject m_boReportObject in m_boReportObjects)
                    {
                        if (m_boReportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                            //get the actual subreport object
                            m_boSubreportObject = (SubreportObject) m_boReportObject;
                       
                           //set subreport background to highlight yellow
                            m_boSubreportObject.Border.BackgroundColor = System.Drawing.Color.Yellow;
                        }
                    }
                }

                //show in reportviewer
                crystalReportViewer1.ReportSource = m_boReportDocument;

    Keywords

    How modify subreport .NET SDK , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

    Product

    Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2 ; SAP Crystal Reports, developer version for Microsoft Visual Studio