Skip to main content


Access to ReportObjects of SAP Crystal Reports Programmatically

When you intend to create report utilizing SAP Crystal Reports for Visual Studio 2012, generally speaking, all the report content can be bound with some kinds of data source (like DataSet). However, in some particular scenarios, some report content is not bound to any data source, and you have to change them dynamically, such as report title, report filter criterion, this post introduces you to change the report object attributes programmatically in Visual Studio 2012.

Using libraries:

using CrystalDecisions.Shared;

using CrystalDecisions.CrystalReports.Engine;

Then you need to find the section ID and report object ID in crystal report designer, the following piece of C# code can update the text of the report objects, such as report title, report footer and filter criterion:

ReportClass rpt = new MyReport();

((TextObject)rpt.ReportDefinition.Sections[2].ReportObjects[“Text_ReportTitle”]).Text = param.ReportTitle;

            ((TextObject)rpt.ReportDefinition.Sections[2].ReportObjects[“Text_ReportFooter”]).Text = param.ReportFooter;

            ((TextObject)rpt.ReportDefinition.Sections[2].ReportObjects[“Text_FilterParameters”]).Text = param.ReportQuery;

Also, you can access some other attributes like object position, height, width, suppress, background color and so on.

((TextObject)rpt.ReportDefinition.Sections[2].ReportObjects[“Text_Field1”]).Width = colWidth;

((TextObject)rpt.ReportDefinition.Sections[2].ReportObjects[“Text_Field1]).ObjectFormat.EnableSuppress = true;

((FieldObject)rpt.ReportDefinition.Sections[3].ReportObjects[“DataColumn1]).Height = colHeight;

 ((FieldObject)rpt.ReportDefinition.Sections[3].ReportObjects[“DataColumn1”]).ObjectFormat.EnableSuppress = true;

There are good hints in case you need to create dynamic crystal report with SAP Crystal Report for Visual Studio 2012.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Richard Yang

More from this Author

Follow Us