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
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";

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With