Skip to Content

Create Text Object for Report at Runtime

Hi folks,

I know how to change the text of a Text Object from a c# program but what I need to know is how to create a Text Object and insert it into a section of a crystal report.

I cant create the Text Objects at design time as I don't know how many I will need to create till runtime.

I was looking for a method something like:

rep.ReportDefinition.Sections["Section1"].ReportObjects.Add(new TextObject())

But Add() does not appear to be a method of ReportObjects class.

Can this be done ?


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Feb 06, 2018 at 10:56 PM

    Hi John,

    Dell's is the easist to use but if you want to add new text objects here's how to...

    You can't just add an object, you need to clone an exist object first:

    case CrReportObjectKindEnum.crReportObjectKindText:
    CrystalDecisions.ReportAppServer.ReportDefModel.TextObject txtObj;
    txtObj = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)rptObj1;

    btnReportObjects.Text += txtObj.Name.ToString() + "\n Kind: " + rptObj1.Kind.ToString() + " -> " + txtObj.Text.ToString();
    btnReportObjects.Text += "\nEnableSuppressEmbedBlankLines: " + ((dynamic)rptObj1).TextObjectFormat.EnableSuppressEmbedBlankLines + "\n";
    btnReportObjects.Text += "SectionCode: " + ((dynamic)rptObj1).SectionCode + "\n";
    btnReportObjects.AppendText("ToolTip: " + rptObj1.Format.ToolTipText.ToString() + "\n\n");
    btnCount.Text = flcnt.ToString();

    This works do not change
    if (txtObj.Name == "Text6")
    CrystalDecisions.ReportAppServer.ReportDefModel.TextObject OldTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)rptObj1;
    CrystalDecisions.ReportAppServer.ReportDefModel.TextObject NewTextObject = new CrystalDecisions.ReportAppServer.ReportDefModel.TextObject();

    //OldfieldObject.CopyTo(NewfieldObject, true);

    NewTextObject = (CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)OldTextObject.Clone(true);
    // to modify the field text object see this KBA - SCN forum post
    // See forum post
    // Also see note 1254721

    NewTextObject.Border.BackgroundColor = 255;

    rptClientDoc.ReportDefController.ReportObjectController.Modify(OldTextObject, NewTextObject);
    //rptClientDoc.ReportDefController.ReportObjectController.Modify(OldTextObject, NewTextObject);

    IsRpt = false;

    Code is in the Parameter sample on the download WIKI:


    Add comment
    10|10000 characters needed characters exceeded

  • Dec 11, 2017 at 09:33 PM

    Is there a maximum number of text objects that there might be for the report? If so, here's what I would do:

    1. Create a new section for each possible text object. For example, if they're supposed to be in a group footer, then you would create multiple group footer sections at the same group level.

    2. In the Section Expert, turn on "Suppress if blank" for all of the sections from Step 1.

    3. Put a blank text block in each of the sections created in Step 1. Make it as wide as it needs to be for your report format (this may be the width of the page, etc.

    4. For each text block, right-click and select "Format Text". Give the text object a name that you can use in your code to set the text value.

    Now, in your code, set the appropriate text for as many of the text objects as you need to use and then ignore the others. The sections that they're in won't print due to the "Suppress if Blank" setting.


    Add comment
    10|10000 characters needed characters exceeded