Development

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:

Covid 19
COVID-19: Digital Insights For Enterprise Action

Access Perficient’s latest insights into how you can leverage digital technologies to not only respond to the pandemic, but drive your operations forward and deliver experiences your customers need.

Get Informed

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.

About the Author

More from this Author

Leave a Reply

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

Subscribe to the Weekly Blog Digest:

Sign Up