Assuming that I have two separate reports and I want to show it in a crystal report viewer then print it.
I have tried the number 1 solution in this link reference. I put 2 crystal report viewer in my Winforms
.
then I use the code below but only one report is shown and printed.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class frmStPeter
Private Sub frmStPeter_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim c As Integer
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
doctoprint.PrinterSettings.PrinterName = "EPSON L120 Series on PC1"
Dim Report As New ReportDocument
Report.Load("C:\CRep\stPeter.rpt")
Report.Load("C:\CRep\stAnthony.rpt")
Dim rawKind As Integer
For c = 0 To doctoprint.PrinterSettings.PaperSizes.Count - 1
If doctoprint.PrinterSettings.PaperSizes(c).PaperName = "ClassSchedule" Then
rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(c).GetType().GetField("kind", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(c)))
Exit For
End If
Next
Report.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)
Report.PrintToPrinter(1, False, 1, 1)
CR1.ReportSource = Report
CR2.ReportSource = Report
CR1.Refresh()
CR2.Refresh()
End Sub
End Class
Update. I did it this way. the print was successful but i only view the first report in the report viewer. I cannot find the settings to view my two reports at the same time
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class frmStPeter
Private Sub frmStPeter_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim c As Integer
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
doctoprint.PrinterSettings.PrinterName = "EPSON L120 Series on PC1"
Dim Report As New ReportDocument
Dim Report1 As New ReportDocument
Report.Load("C:\CRep\stPeter.rpt")
Report1.Load("C:\CRep\stanthony.rpt")
Dim rawKind As Integer
For c = 0 To doctoprint.PrinterSettings.PaperSizes.Count - 1
If doctoprint.PrinterSettings.PaperSizes(c).PaperName = "ClassSchedule" Then
rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(c).GetType().GetField("kind", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(c)))
Exit For
End If
Next
Report1.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)
Report1.PrintToPrinter(1, False, 1, 1)
Report.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)
Report.PrintToPrinter(1, False, 1, 1)
CR1.ReportSource = Report
CR2.ReportSource = Report1
CR2.Refresh()
CR1.Refresh()
End Sub
End Class
Can anyone please help me to solve this. Thank you