Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change text of Text Object in Crystal Report Programmatically

i got many same text objects in crystal report which i want to change text of them using c#.net this is my code:

TextObject textObj = (TextObject)MyReport.Sections[2].ReportObjects[3];

but i cant change text of textObj


1 Answers

I don't think you reference the location of the text object rather than it's name. So try something like:

CrystalDecisions.CrystalReports.Engine.TextObject txtReportHeader;
txtReportHeader = MyReport.ReportDefinition.ReportObjects["txtHeader"] as TextObject;
txtReportHeader.Text = "My Text";

"txtHeader" would be the name of the text object in your report.

EDIT: You can change the value of a text at runtime. You do not need to delete and create a new label. I adapted the code to work for one of my reports and changed the label "locid" to "My Text". See screenshot. Here is the code:

using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;


CrystalDecisions.CrystalReports.Engine.TextObject txtReportHeader;
            txtReportHeader = CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["text3"] as TextObject;
            txtReportHeader.Text = "My Text";

enter image description here

like image 127
campagnolo_1 Avatar answered Dec 31 '25 06:12

campagnolo_1