'********************************************
'Created: January 17, 2002
'Author ID: JAS
'Purpose: This Visual Basic .NET sample Windows application demonstrates
' accessing a subreports (in a main report) at runtime.
'*********************************************
''Both of these CR assemblies are required to be able to
''access, load, and access subreports.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Inherits System.Windows.Forms.Form
''CR Variables
Dim crReportDocument As MainReport
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crSubreportDocument As ReportDocument
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
''Create an instance of the strongly-typed MAIN report object
crReportDocument = New MainReport()
''Get all the sections in the report
crSections = crReportDocument.ReportDefinition.Sections
''Loop through each section of the report...
For Each crSection In crSections
''Get all the report objects from each section
crReportObjects = crSection.ReportObjects
''Loop through each report object...
For Each crReportObject In crReportObjects
''Check to see if the report object is a subreport
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
''Found the subreport.
''Get the actual subreport object
crSubreportObject = CType(crReportObject, SubreportObject)
''Get the subreport as a regular report object.
''The OpenSubreport returns the subreport object as a report
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
''Display the name of the subreport.
MessageBox.Show("Subreport Name: '" & crSubreportDocument.Name & "'")
End If
Next ''Go to the next report object
Next ''Go to the next section
''Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReportDocument
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.CrystalReportViewer1 = New CrystalDecisions.Windows.Forms.CrystalReportViewer()
Me.SuspendLayout()
'
'CrystalReportViewer1
'
Me.CrystalReportViewer1.ActiveViewIndex = -1
Me.CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
Me.CrystalReportViewer1.ReportSource = Nothing
Me.CrystalReportViewer1.Size = New System.Drawing.Size(292, 273)
Me.CrystalReportViewer1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CrystalReportViewer1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)