'How to print Using Crystal Reports
I have developed a vb.net application. My application offers some reporting facilities like sales report etc...I have generated the report by using the dataset option i.e. setting the dataset to be the source for the crystal report. I just want my application to print the report when the user clicks the "generate report" button on the Windows Form...Can anyone help me on how can I achieve this??
Solution 1:[1]
I use something along the lines off:
Imports in the class:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Windows.Forms
And then:
Private sub print_report()
For parameters etc
Dim pFields As New ParameterFields()
Dim pField As New ParameterField()
Dim disVal As New ParameterDiscreteValue()
Try
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim report_to_print As New report_name
add parameters (ignore if not neeeded)
report_to_print.SetParameterValue("@parameter", parameter)
You also need a form that holds the crystal report viewer control (here frmReportViewer) and pass the report to it (code for this after)
Dim frmReportViewer As New frmReportViewer(report_to_print)
pass parameters (if required)
frmReportViewer.cryrepviewer.ParameterFieldInfo = pFields
show report
frmReportViewer.ShowDialog()
Catch ex As System.Exception
'your own error handling code here
Finally
Cursor.Current = System.Windows.Forms.Cursors.Default
End Try
End Sub
frmReportViewer - this contains display, saving, printing controls :
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class frmReportViewer Inherits System.Windows.Forms.Form
Dim mViewerRep As New ReportDocument
Public Sub New(ByVal pViewerRep As ReportDocument)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
mViewerRep = pViewerRep
End Sub
Private Sub cryRepViewer_Load() Handles cryrepviewer.Load
cryrepviewer.ReportSource = mViewerRep
cryrepviewer.Refresh()
Me.Text = ""
End Sub
End Class
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Amy |
