Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Change Text Object at Runtime Post Reply Post New Topic
Page  of 2 Next >>
Author Message
BernieHunt
Newbie
Newbie


Joined: 03 Apr 2007
Location: United States
Online Status: Offline
Posts: 21
Quote BernieHunt Replybullet Topic: Change Text Object at Runtime
    Posted: 03 Apr 2007 at 8:36pm
I'm having a terrible time getting the syntax for this. I have a Crystal report embedded in my VS05 VB.net application. I create a dataset using multiple database queries. I think instantiate a crViewer and load my report into the viewer and load my dataset into the report. All of this works.
 
I now want to add changing some of the text items on the report before I display it.
 
So far I have;
 
    frmReportForm = New frmReportViewer
    crThisReport = New Pat_Statement
    crThisReport.SetDataSource(dsPatData)
  
    crThisReport.ReportDefinition.ReportObjects.Item["Text12"] = _
         "mySting info"
 
This last line is where I'm having the syntax problem. In this example, Text12 is the name of the text object on the report.
 
Any anyone point me in the right direction or point me to a good resource that has how to access all the objects on a report?
 
I looked all through BO's documentation and there wasn't much on highly embedded reports in VS.
 
Thanks,
Bernie
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 03 Apr 2007 at 10:29pm
My book gives you a reference on the ReportDocument object model. It is for VS 2003, but the object model is about 95% the same. So this should be a big help for making your runtime changes.

For your formula you need to cast the object as a TextObject. Then assign the string to the .Text property. That should clear up your errors. Chapter 15 has lots of source code if you plan on doing more runtime changes like this.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 03 Apr 2007 at 10:30pm
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
BernieHunt
Newbie
Newbie


Joined: 03 Apr 2007
Location: United States
Online Status: Offline
Posts: 21
Quote BernieHunt Replybullet Posted: 04 Apr 2007 at 6:45am
Argh! Still striking out with
 

((CrystalDecisions.Shared.ReportObjectKind.TextObject)crThisReport.ReportDefinition.ReportObjects.Item("Text12")).text = "new text"

I ordered the book so I guess I'll have to wait a week to work on this some more.

Bernie
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 04 Apr 2007 at 9:48am
You're code isn't making sense. You're cast has too many parentheses on the left and is C# syntax, but your array indexer is VB.NET because it uses a parentheses instead of a square bracket. Which language are you using?

If VB.NET, then use CType() to cast it. If using C# then use ReportObjects["Text12"].Text to reference the array.

You have the right idea, but the code is buggy.


Edited by BrianBischof - 04 Apr 2007 at 9:49am
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
BernieHunt
Newbie
Newbie


Joined: 03 Apr 2007
Location: United States
Online Status: Offline
Posts: 21
Quote BernieHunt Replybullet Posted: 04 Apr 2007 at 10:17am
Argh!
 
Hahahaha, the parentheses syntax is actually right for Java, the problem is I'm writing in VB. I hate switching languages mid week.
 
Thanks and I'm looking forward to the book.
 
Also, would your Crystal Reports Encyclopedia be of interest? I work only with imbeded reports.
 
Thanks,
Bernie
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 04 Apr 2007 at 10:35am
Yes, using multiple languages can make things confusing.

Volume 1 of the CR Encyclopedia will not address ANY programming topics at all. It is strictly an XI book. Volume 2 is 100% VS 2005. So Volume 2 is the one you'll want.

However, I'm going to have a lot more report samples in Volume 1 and if that appeals to you then you can check that out as well. But again, it has no code in it.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
craigb
Newbie
Newbie


Joined: 15 Mar 2007
Online Status: Offline
Posts: 3
Quote craigb Replybullet Posted: 18 Apr 2007 at 8:11am

'Load report first
MyReport.Load(reportPath)


'Change text of a tet object
Dim myTextObjectOnReport As CrystalDecisions.CrystalReports.Engine.TextObject


myTextObjectOnReport = CType(MyReport.ReportDefinition.ReportObjects.Item("NameOfTextObject"), CrystalDecisions.CrystalReports.Engine.TextObject)

myTextObjectOnReport.Text = "Text you want for text object"
IP IP Logged
MarkM
Newbie
Newbie
Avatar

Joined: 01 May 2007
Location: United States
Online Status: Offline
Posts: 5
Quote MarkM Replybullet Posted: 01 May 2007 at 9:03am
Has anyone got this to work using VB.Net 2005 & CRXI R2?
I have seen this solution on several sites and have tried it in the form load event and with a button on the form after the CRviewer has loaded (below)...no joy.  The variable "myTextObjectOnReport" text changes no problem but it has no affect on the textObject on the report....any thoughts?
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim myTextObjectOnReport As CrystalDecisions.CrystalReports.Engine.TextObject

myTextObjectOnReport = CType(CustOrder1.ReportDefinition.ReportObjects.Item("txtName"), CrystalDecisions.CrystalReports.Engine.TextObject)

myTextObjectOnReport.Text = "isThisWorking"

End Sub

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 01 May 2007 at 10:05am
I'm concerned about putting this in the Click event of a button. Has the report already been displayed to the user and then the user clicks on the button? Or are they clicking on the button and then something else displays the report? My theory is that your object reference isn't working either because the report is already displayed or it gets displayed later and the object reference is lost.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.008 seconds.