Reputation: 185643
While I realize that I could just show the form off-screen and hide it, along with many other forms of WinForms hackish wizardry, I'd rather stick with the zen path and get this done right. I have a SSRS local report (so no server) that I want to give the user the option of either viewing or printing (in other words, I don't want to force them to view to print). Unfortunately, the ReportViewer control complains about its "state" when I try to print it either as a component I'm creating explicitly in my code (inside a using() block, of course) or if I try to instantiate my viewer form and just print without ever showing it.
Is there a means to do this that will sit well with me, or should I just show it off-screen and move on with my life?
Upvotes: 14
Views: 51842
Reputation: 1
Private Sub btnReceipt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceipt.Click
My.Forms.FormA5.ReportViewer.LocalReport.DataSources.Clear()
Dim cmd = New SqlClient.SqlCommand("Select * from V_Sale where InvoiceNo=" & Me.txtInvoice.Text, cn)
Dim dr = cmd.ExecuteReader()
Dim dt As New DataTable
dt.Load(dr)
dr.Close()
Dim rpt As New ReportViewer
rpt.LocalReport.DataSources.Clear()
rpt.LocalReport.DataSources.Add(New ReportDataSource("posds_receipt", dt))
rpt.LocalReport.ReportEmbeddedResource = "POSsystem.receipt.rdlc"
rpt.SetDisplayMode(DisplayMode.PrintLayout)
rpt.ZoomMode = ZoomMode.FullPage
Dim printDialog1 As PrintDialog = New PrintDialog
printDialog1.Document = PrintDocument1
Dim result As DialogResult = printDialog1.ShowDialog
If (result = DialogResult.OK) Then
PrintDocument1.Print()
End If
End Sub
Upvotes: 0
Reputation: 1
Please see the below link very useful for you http://social.msdn.microsoft.com/Forums/en-US/9f52d79d-5baf-4e84-97d5-7dbba6623b89/printing-without-the-reportviewer
Upvotes: 0
Reputation: 394
I have a sample that does this posted on my blog here: http://blogs.msdn.com/brianhartman/archive/2009/02/27/manually-printing-a-report.aspx
The LocalReport object can be instantiated independently of the ReportViewer control and used directly in the sample code attached to that blog post. Or you can pass in ReportViewer.LocalReport even if you don't first display the report in the UI.
Upvotes: 22
Reputation: 1336
Check this out and see if it helps...http://scruffylookingcatherder.com/archive/2007/12/07/printing-reporting-services-2005-reports.aspx
A little explanation: It's using the SSRS web service to render the report to an EMF image then send the image to the printer.
Upvotes: 1