Adding a subreport to Active Reports
I'm writing a report in VB .NET (using Active Reports) that displays details about a location, and then displays a bunch of images, which are stored in a database. The images are displayed in my main report via a subreport.
Howev开发者_如何学Goer, I can't get the images to load. I have two files, the main report (rptMain) and the image subreport (rptSubImages). The sub Detail1_Format in the rptSubImages never gets ran, which is why the images are not appearing, and I can't figure out why! I've included the code below... can anyone pinpoint why my subreport detail section isn't getting called? The rptSubImages report gets initialized, but if I put a stop point inside the detail sub, it never gets caught during debug.
Here is the code:
rptMain:
Imports DataDynamics.ActiveReports
Imports DataDynamics.ActiveReports.Document
Imports System.Data
Imports System.Data.OleDb
Public Class rptMain
Private rpt As rptSubImages
Private Sub rptMain_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ReportStart
End Sub
Private Sub Detail1_Format(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Detail1.Format
Me.SubReport2.Report = rpt
Dim cmd As New OleDbCommand("rptMain")
cmd.Parameters.Add("@LocationID", OleDbType.Integer).Value = locationID
Windows.Forms.Cursor.Current = Cursors.WaitCursor
Dim dsLocationInfo As DataSet = objPlugIn.GetProcDataset(cmd, Aquifer.PlugIn.DataFormat.Compressed)
'--image
Dim dtImage As DataTable = dsLocationInfo.Tables(1)
If dtImage.Rows.Count > 0 Then
rpt = New rptSubImages
SubReport2.Report = rpt
SubReport2.Report.DataSource = dtImage
End If
End Sub
End Class
rptSubImages:
Imports DataDynamics.ActiveReports
Imports DataDynamics.ActiveReports.Document
Public Class rptSubImages
Public Sub New()
InitializeComponent()
End Sub
Private Sub Detail1_Format(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Detail1.Format
'some text
End Sub
End Class
Solved my own problem :) I bumped the section that created and set values of the subreport out of Detail_Format and put it in ReportStart of rptMain, and voila, it loads :) I just had it in the wrong part of the main form!
You can get more information on SubReports here:
http://blogs.gcpowertools.co.in/2011/09/how-to-control-sub-report-from-parent.html
精彩评论