cancel
Showing results for 
Search instead for 
Did you mean: 

Find out the section of a text object

Former Member
0 Kudos

Using the answer of this post I managed to dynamically create and add a formula field on my report, but I need to find the section of a text object because I want to replace the content of that text object with the formula field.

Thank you in advance!

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Mihai,

This should get you started, it returns most info about the objects and you should be able to find the objects. Note, dumps the output into a text box:

btnReportObjects.Text = "";

flcnt = 0;

CrystalDecisions.ReportAppServer.ReportDefModel.ReportObjects rptObjs;

//rptObjs = rptClientDoc.ReportDefController.ReportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField);

rptObjs = rptClientDoc.ReportDefController.ReportObjectController.GetAllReportObjects();

foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject rptObj1 in rptObjs)

{

    switch (rptObj1.Kind)

    {

        case CrReportObjectKindEnum.crReportObjectKindField:

            CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject fldObj1;

            fldObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)rptObj1;

                               

            textBox1 = fldObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += fldObj1.DataSourceName.ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindText:

            CrystalDecisions.ReportAppServer.ReportDefModel.TextObject txtObj;

            txtObj = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)rptObj1;

            textBox1 = txtObj.Name.ToString();

            textBox1 += " -> ";

            textBox1 += txtObj.Text.ToString();

            textBox1 += "EnableSuppressEmbedBlankLines: " + ((dynamic) rptObj1).TextObjectFormat.EnableSuppressEmbedBlankLines + "\n";

            btnReportObjects.Text += textBox1;

            textBox1 += "SectionCode: " + ((dynamic) rptObj1).SectionCode;

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

        case CrReportObjectKindEnum.crReportObjectKindBox:

            CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject boxObj1;

            CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject boxObj2 = new CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject();

            boxObj1 = (CrystalDecisions.ReportAppServer.ReportDefModel.BoxObject)rptObj1;

            boxObj2 = boxObj1;

            //// modify the box size

            //boxObj.Bottom = 360;

            //boxObj1.Height = 2385;

            //boxObj1.Format.EnableCanGrow = true;

            //boxObj1.EndSectionName = "ReportFooterSection1";

            //boxObj1.EnableExtendToBottomOfSection = true;

            //rptClientDoc.ReportDefController.ReportObjectController.Modify(boxObj, boxObj1);

            textBox1 = boxObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += boxObj1.Name.ToString();

            textBox1 += " : X - ";

            textBox1 += (boxObj1.Left / 1440.00).ToString();

            textBox1 += " : Y - ";

            textBox1 += ((boxObj1.Right - boxObj1.Left) / 1440.00).ToString();

            textBox1 += " : Width - ";

            textBox1 += (boxObj1.Width / 1440.00).ToString();

            textBox1 += " : Height - ";

            textBox1 += (boxObj1.Height / 1440.00).ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            IsRpt = false;

            break;

        case CrReportObjectKindEnum.crReportObjectKindPicture:

            textBox1 = rptObj1.Name.ToString();

            textBox1 += " -> ";

            textBox1 += rptObj1.Name.ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            btnReportObjects.Text += "Height: " + rptObj1.Height.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Width: " + rptObj1.Width.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Top: " + rptObj1.Top.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Left: " + rptObj1.Left.ToString();

            btnReportObjects.AppendText(" Twips\n");

            btnReportObjects.Text += "Section Name: " + rptObj1.SectionName.ToString();

            btnReportObjects.AppendText("\n");

            ++flcnt;

            btnCount.Text = flcnt.ToString();

            break;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindSubreport;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindOlapGrid;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindMap;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindLine;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindInvalid;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindFlash;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindFieldHeading;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindCrosstab;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindChart;

    //CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindBlobField;

    }

}

Output looks like this:

ReportTitle1 -> ReportTitle

DistinctCountofFixRequestID1 -> DistinctCount ({Fix_Request_View.Fix_Request_ID})

Picture3 -> Picture3

Height: 710 Twips

Width: 1440 Twips

Top: 10 Twips

Left: 240 Twips

Section Name: ReportHeaderSection6

FileAuthor1 -> FileAuthor

DataDateTime1 -> {@DataDateTime}

Text16 -> {Fix_Request_View.DEV_Target_Milestone} - Total: DistinctCount ({Fix_Request_View.Fix_Request_ID}, {Fix_Request_View.DEV_Target_Milestone})EnableSuppressEmbedBlankLines: False

Text16 -> {Fix_Request_View.DEV_Target_Milestone} - Total: DistinctCount ({Fix_Request_View.Fix_Request_ID}, {Fix_Request_View.DEV_Target_Milestone})EnableSuppressEmbedBlankLines: False

SectionCode: 3000

Text19 -> Total GroupName ({Fix_Request_View.Fix_Request_State}) : DistinctCount ({Fix_Request_View.Fix_Request_ID}, {Fix_Request_View.Fix_Request_State}) EnableSuppressEmbedBlankLines: False

Text19 -> Total GroupName ({Fix_Request_View.Fix_Request_State}) : DistinctCount ({Fix_Request_View.Fix_Request_ID}, {Fix_Request_View.Fix_Request_State}) EnableSuppressEmbedBlankLines: False

SectionCode: 3001

Field51 -> {Problem_Report_Table.synopsis}

id1 -> {Problem_Report_Table.id}

Don

Former Member
0 Kudos

Thank you, this is pure gold!

Using:

section=ReportClientDocument.ReportDefController.ReportDefinition.

FindSectionByName(((dynamic) rptObj1).SectionName)


I managed to get it.

Answers (0)