Ticket Q336182
Visible to All Users
Duplicate

How to print report direct, and print preview via an simple action?

created 14 years ago

HI
may i know have any sample to teach
How to print report direct, and print preview via an simple action?
thanks
Sze Yuan

Answers approved by DevExpress Support

created 14 years ago (modified 12 years ago)

Hello,
Thank you for the question.
Here is the code you can use to get a report from an arbitrary place in your application:

C#
IReportData reportData = ObjectSpace.FindObject<ReportData>(new BinaryOperator("Name", "MyReportName")); if(reportData != null) { using(IObjectSpace os = Application.CreateObjectSpace()) { XafReport report = reportData.LoadXtraReport(os); DoSomethingWithReport(report); } } public void DoSomethingWithReport(report) { //You can print it: //ReportPrintTool printTool = new ReportPrintTool(report); //printTool.Print(); //Or you can export it: report.ExportToPdf("MyReport.pdf", report.ExportOptions.Pdf); //etc. }

If you want, you can access a ready report reference from WinReportServiceController.CustomShowPreview event arguments.
Let me know if I can help you further.
Thanks,
Dennis
P.S.
Can I make this ticket public? Also, can you please make your future tickets (if possible) public as well?
---------------
Check if Search Engine is able to answer questions faster than I do!
---------------

    Show previous comments (3)
    Dennis Garavsky (DevExpress) 14 years ago

      Great, thank you for informing us of your results!
      Regards,
      Dennis

        Hi,
        I have tried this:
        Dim reportData As IReportDataV2 = DirectCast(ObjectSpace.FindObject(Application.Modules.FindModule(Of ReportsModuleV2)().ReportDataType, New BinaryOperator("DisplayName", "Bill")), IReportDataV2)
             Dim report = ReportDataProvider.ReportsStorage.LoadReport(reportData)
             With report
                report.RequestParameters = False
                report.Parameters("p_key").Value = hdr.bill_hdr_key

        Dim printTool As New ReportPrintTool(report)
                printTool.Print()
             End With
        Why is it printing a blank report even if it has properly passed the value of the parameter?  What am I missing?

        Dennis Garavsky (DevExpress) 9 years ago

          Hello,

          To process your recent post more efficiently, I created a separate ticket on your behalf: T319008: An empty report can be produced when loading a report data and printing XtraReport programmatically. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.