SAP Knowledge Base Article - Public

1288988 - How to add a group to a report using the Crystal Reports .NET inproc RAS SDK

Symptom

How to add a group to a report using the Crystal Reports .NET inproc RAS SDK?

Reproducing the Issue

  • Crystal Reports XI Release 2 Service Pack 2 and later 
  • C#

Resolution

sample code:

         using CrystalDecisions.CrystalReports.Engine;
         using CrystalDecisions.ReportAppServer.Controllers;
         using CrystalDecisions.ReportAppServer.ClientDoc;
         using CrystalDecisions.ReportAppServer.DataDefModel;

        //CR Declarations
        ReportDocument                                                                      m_boReportDocument;
        ISCDReportClientDocument                                                   m_boReportClientDocument;
        CrystalDecisions.ReportAppServer.DataDefModel.Group m_boGroup;
       
        int m_boTableIndex;
        CrystalDecisions.ReportAppServer.DataDefModel.Table  m_boTable;
        CrystalDecisions.ReportAppServer.DataDefModel.Field   m_boField;

         m_boReportDocument = new ReportDocument();

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

         //access the ReportClientDocument in the ReportDocument (EROM bridge)
         m_boReportClientDocument = boReportDocument.ReportClientDocument;

         //create a new Group Object
         m_boGroup = new CrystalDecisions.ReportAppServer.DataDefModel.Group();

         //now find the database field that will be used as the grouping condition - 
         //you can reference it directly, but this method can be used if you only know the table name
         m_boTableIndex = boReportClientDocument.DatabaseController.Database.Tables.FindByAlias("Customer");
         m_boTable = (CrystalDecisions.ReportAppServer.DataDefModel.Table)boReportClientDocument.DatabaseController.Database.Tables[boTableIndex];

          //get the field in the Table
          m_boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boTable.DataFields.FindField("{Customer.City}",
          CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula,
          CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);

          //set that field as the field to group on
          m_boGroup.ConditionField = m_boField;

          //add it to the report
          m_boReportClientDocument.DataDefController.GroupController.Add(-1, m_boGroup);

           //display in reportviewer
           crystalReportViewer1.ReportSource = m_boReportDocument;

Keywords

How add group Crystal Reports .NET inproc RAS SDK , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

SAP Crystal Reports XI R2