Skip to Content

Once I wanted to find a field of a Crystal Report and manipulate its property. When I learnt about ReportObject things become simpler as it helped me find all of them. Let’s learn a little about it.

What is ReportObject?

ReportObject could be a database field, text labels, cross-tab, binary large objects, horizontal or vertical lines etc.. For e.g. TextObject, BoxObject, CrossTab Object etc…

For SDK it is a base class providing generic properties for various kinds of report objects. To use this with our project we need to include CrystalDecisions.CrystalReports.Engine Namespace.

The CrystalDecisions.CrystalReports.Engine namespace provides support for the ReportDocument object model, so I would say that it is available only when we use ReportDocument object model (For more on Object Models, see Crystal Reports .NET Applications and Object Models used).

ReportObject has two members Count and Item. Object of the report can be retrieved either by name or its index through Item. Rather than retrieving any specific object I am retrieving all the objects of a report and subreport(s) as well.

You can modify the code to suit your needs. Following code helps you find the ReportObjects in main report.

Sample Code for Finding Objects in Main Report

private void FindObjectsinMainReport()

    {

        ReportDocument reportDocument = new ReportDocument();

        string reportPath = Server.MapPath(“CrystalReports.rpt”);

        reportDocument.Load(reportPath);

        if (reportDocument.ReportDefinition.ReportObjects.Count > 0)

        {

            Response.Write(“</br>”);

            Response.Write(“<table border=1 cellspacing=2>”);

            Response.Write(“<tr>”);

            Response.Write(“<td><b>Report Object Name</b></td>”);

            Response.Write(“<td><b>Report Kind</b></td>”);

            Response.Write(“<td><b>Report Object Format</b></td>”);

            Response.Write(“</tr>”);

            foreach (ReportObject reportObject in reportDocument.ReportDefinition.ReportObjects)

            {

                Response.Write(“<tr>”);

                Response.Write(“<td>” + reportObject.Name + ” </td>”);

                Response.Write(“<td>” + reportObject.Kind.ToString() + ” </td>”);

                Response.Write(“<td>” + reportObject.ObjectFormat.ToString() + ” </td>”);

                Response.Write(“</tr>”);

            }

            Response.Write(“</table>”);

        }       

    }

For finding ReportObjects in Subreport(s) use following:

Sample Code for Finding Objects in Subreports

private void FindObjectsinSubReports()

    {

        ReportDocument reportDocument = new ReportDocument();

        string reportPath = Server.MapPath(“CrystalReports.rpt”);

        reportDocument.Load(reportPath);

        if (reportDocument.Subreports.Count > 0)

        {

            foreach (ReportDocument rdoc in reportDocument.Subreports)

            {

                if (rdoc.ReportDefinition.ReportObjects.Count > 0)

                {

                    Response.Write(“</br>”);

                    Response.Write(“<table border=1 cellspacing=2>”);

                    Response.Write(“<tr>”);

                    Response.Write(“<td><b>Report Object Name</b></td>”);

                    Response.Write(“<td><b>Report Kind</b></td>”);

                    Response.Write(“<td><b>Report Object Format</b></td>”);

                    Response.Write(“</tr>”);

                    foreach (ReportObject reportObject in rdoc.ReportDefinition.ReportObjects)

                    {

                        Response.Write(“<tr>”);

                        Response.Write(“<td>” + reportObject.Name + ” </td>”);

                        Response.Write(“<td>” + reportObject.Kind.ToString() + ” </td>”);

                        Response.Write(“<td>” + reportObject.ObjectFormat.ToString() + ” </td>”);

                        Response.Write(“</tr>”);

                    }

                    Response.Write(“</table>”);

                }

            }

        }

Most of the objects inherit the properties of ReportObject, some of them inherit all and some few. Here’s the table listing all of them:

BlobFieldObject ChartObject Properties CrossTabObject
FlashObject Properties GraphicObject MapObject
OlapGridObject PictureObject BoxObject
DrawingObject FieldHeadingObject FieldObject
LineObject SubReportObject TextObject

I started writing this blog last year and completing it now, didn’t notice that calendar on the wall has changed, though I am late, but Happy New Year SCN.

Note: I have published the blog long time back, with the new Jive platform I have edited some of the stuff to make few things prominent in the blog

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply