Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: change text field in subreport Post Reply Post New Topic
Author Message
Enzyme80
Newbie
Newbie


Joined: 19 Jan 2007
Location: United States
Online Status: Offline
Posts: 27
Quote Enzyme80 Replybullet Topic: change text field in subreport
    Posted: 17 Mar 2009 at 7:46am
Wondering if it is possilbe to change the text of a text object at runtime that is in a subreport.
 
I know you can do this in the main report by something like
 
dim strRCSZ as string
Dim rptTxtGroup As TextObject    
strRCSZ = "my info"
rptTxtGroup = rpt.ReportDefinition.ReportObjects.Item("Text1")
rptTxtGroup.Text = strRCSZ

Basically I want to do the exact same thing but for the subreport, i just can't figure it out.



Edited by Enzyme80 - 17 Mar 2009 at 8:37am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 17 Mar 2009 at 1:15pm
You have to find the subreport and get to it's fields.  It's like setting the table logins for subreports in code.
 
Assuming you're using the ReportDocument object model, I think it will look something like this:
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
  ReportObjects reportObjects = section.ReportObjects;
  foreach (ReportObject reportObject in reportObjects)
  {
    if (reportObject.Kind == ReportObjectKind.SubreportObject)
    {
      SubreportObject subreportObject = (SubreportObject)reportObject;
      ReportDocument subReportDocument =
        subreportObject.OpenSubreport(subreportObject.SubreportName);
      <add code to set the text object>          
    }
  }
}
 
-Dell
IP IP Logged
Enzyme80
Newbie
Newbie


Joined: 19 Jan 2007
Location: United States
Online Status: Offline
Posts: 27
Quote Enzyme80 Replybullet Posted: 18 Mar 2009 at 12:10pm
Hmm... well apprerantly i used to be better at translating code from c# to vb.net. 
I am using the reportdocument object model but it does not have the reportdefinition in it.  
I will keep trying to convert the code. hopefully it will lead me where I need.
IP IP Logged
Enzyme80
Newbie
Newbie


Joined: 19 Jan 2007
Location: United States
Online Status: Offline
Posts: 27
Quote Enzyme80 Replybullet Posted: 18 Mar 2009 at 12:36pm

here is the VB version of it.  sorry for the long formatting, I just copied and pasted the code from VS 2005.

Dim rpt As ReportDocument = New ReportDocument
Dim rSections As Sections
Dim rSection As Section
Dim sReportObjects As ReportObjects
Dim sReportObject As ReportObject
Dim subReportObject As SubreportObject
Dim subReportDoc As ReportDocument
Dim rptTxtGroup As TextObject
 
rSections = rpt.ReportDefinition.Sections
For Each rSection In rSections
     sReportObjects = rSection.ReportObjects
     For Each sReportObject In sReportObjects
          If sReportObject.Kind = ReportObjectKind.SubreportObject Then
               subReportObject = sReportObject
               subReportDoc = subReportObject.OpenSubreport(subReportObject.SubreportName)
               rptTxtGroup = subReportDoc.ReportDefinition.ReportObjects.Item("Text3")
               rptTxtGroup.Text = "Test"
          End If
     Next
Next
 


Edited by Enzyme80 - 18 Mar 2009 at 12:36pm
IP IP Logged
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.047 seconds.