Question

Faizal Shaji - Codemills on Thu, 11 Aug 2011 12:25:26


How to pass a parameter programmatically to filter the dev express xtra report .

Replies

Kivito on Thu, 11 Aug 2011 13:10:01


hi!

havve you checked this link http://community.devexpress.com/blogs/seth/archive/2011/07/20/accessing-a-report-preview-model-in-lightswitch.aspx ?

cheers!

Kivito

Faizal Shaji - Codemills on Fri, 12 Aug 2011 06:30:20


Actually ,what i want to do is that,i want to click a button in the sales page and the report should open with the invoice of that particular sales no.

Kivito on Fri, 12 Aug 2011 07:28:24


hi! it is simple,

create report based screen and add properties you need as parameters (like InvoiceNo) to screen, create report based on table/query you want to show (im not using LS query parameters for now), set up parameters and filterstring on report (InvoiceNo, "[InvoiceId] = ?InvoiceNo") , and in report screen code behind set "reporttypename" to be name of your report:

 

Private rpm as ReportPreviewModel

Private Sub InvoicePrintScreen_Activated()

            'Assign the name of the report, which you want to preview in this screen.

            rpm = model

Me.ReportTypeName = "ReportName"

End Sub

 

you will see in code behind another sub "customizereportpreviewmodel", there you can add code to setup parameters for report, something like this:

 

Public Sub CustomizeReportPreviewModel(model As DevExpress.Xpf.Printing.ReportPreviewModel)

            AddHandler rpm.RequestDefaultParameterValues, AddressOf ParamsReq

End Sub

 

and in ParamsReq sub:

 

Private Sub ParamsReq(sender As Object, e As EventArgs)

            Try

                rpm.Parameters("InvoiceNo").Value = Me.InvoiceNo  'parameter/local property from your screen

                rpm.Parameters("InvoiceNo").Visible = False 'hide parameter that user cannot change parameters of report

                rpm.AutoShowParametersPanel = False

            Catch ex As Exception

                rpm.AutoShowParametersPanel = True

            End Try

            rpm.CreateDocument()

End Sub

 

and from your sales page in command for printing you can put:

 

Private Sub PrintInvoice_Execute()

Application.ShowInvoicePrintScreen(InvoiceNo) 'me.YourInvoiceList.SelectedItem.InvoiceId

End Sub

 

you probably not need try..catch block, but in my app if something is wrong it will show ReportParameterPanel so i can manually insert values for what i want to print..

hope it helps!

cheers!

Kivito

 

 

Faizal Shaji - Codemills on Fri, 12 Aug 2011 10:30:22


i got an error in the line 

 rpm = model

i am attaching the screenshot of my screen code


Kivito on Fri, 12 Aug 2011 12:51:07


sorry my mistake, put "rpm = model" in "CustomizeReportPreviewModel" sub.. it was "early in the morning" (Sublime).. :)

Public Sub CustomizeReportPreviewModel(model As DevExpress.Xpf.Printing.ReportPreviewModel)

 

rpm = model           

AddHandler rpm.RequestDefaultParameterValues, AddressOf ParamsReq

End Sub

cheers!

Kivito

Dragonalw on Sat, 13 Aug 2011 05:37:14


hi kivito,

thanks for the post.

Yesterday I spend a lot of time to do this ...

And I found I way, but I do not why it is working ...

I did it without the AddHandler, and I just modified the "CustomizeReportPreviewModel" Method.

    Public Sub CustomizeReportPreviewModel(model As DevExpress.Xpf.Printing.ReportPreviewModel)
      model.Parameters("InvoiceNo").Value = Me.InvoiceNo

    End Sub


I know that I have to add an function catching an error, but why it works without the Handler, and why I need it normally?

Thanks.

Markus

Kivito on Sat, 13 Aug 2011 09:33:16


to be honest, i really don't know, i'm also new in all this, on similar way it worked in devexpress for lightswitch beta versions, maybe you have based your report on query, and in my case it is based on table? as i know xtrareports now automatically accepts parameters from query.. but i have not played with that yet.. sorry for not being more helpful..

cheers!

Kivito

MarkA Howell on Mon, 15 Aug 2011 16:22:06


This code works for silently passing parameters to a XtraReports report as long as the report is configured to NOT use a parameter on the query itself.

Create a parameter on the report, then add a FilterString

put this code in your ReportPreviewScreen

I have my ReportPreviewScreen accept 3 Parameters (ReportName,SelectedID,SelectedID2)

This way I only have one preview screen as long as all my reports use only 1 or 2 integers as parameters

Sorry C# guys.  I only have a VB sample

 

 Public Class ReportPreviewScreen
  Dim model As DevExpress.Xpf.Printing.ReportPreviewModel
  ' Do not rename the CustomizeReportPreviewModel
  Public Sub CustomizeReportPreviewModel(model As DevExpress.Xpf.Printing.ReportPreviewModel)
   Me.model = model
   model.Parameters("SelectedID").Value = Me.SelectedID ' Pass the SelectedID parameter to the report
   If Me.SelectedID2 > 0 Then
    model.Parameters("SelectedID2").Value = Me.SelectedID2 ' If a second parameter has been sent, pass it along too
   End If
   model.AutoShowParametersPanel = False ' Do not show the ParametersPanel
   model.CreateDocument()
  End Sub
  Private Sub ReportPreviewScreen_Activated()
   Me.ReportTypeName = Me.ReportName ' Assign the name of the report, which you want to preview in this screen.
  End Sub

 End Class



 

 

Good luck,

Mark 


lorenzo77vr on Thu, 25 Aug 2011 22:59:28


Hi,
I'm a young "programmer" with low ability (and bad english! LOL).

I don't understand your solution but you say it work.. can you help me for a step by step solution?

I spent 12 hours today.. but nothing :-(

Thanks

Lorenzo


Dave Vorgang on Sun, 28 Aug 2011 02:23:06


Hi Mark,

Are you sure you need the model.CreateDocument? 

I had it at first and it made the report very incosistant.  Sometimes you can run it 3 times in a row and it works then the next time it's like there is no data.

Also, SQL Profiler show it was trying to get the data twice.  Once I removed the CreateDocument it worked fine.  I was using a parameratized query.

Dave

Kivito on Sun, 28 Aug 2011 14:46:28


hi!

i think that "createdocument" is there cause in dx 11.1.5 or 6, im not sure anymore, when you pass custom parameters (not from query) it would open parameter panel and waited for you to click submit.. but as i said, i didnt use query with parameters.. and now they have new version which fixes many bugs, like deployment to server and calling reports from VB (famous unable to load one or more.. -error)..

@lorenzo:

have you checked devexpress video tutorials for creating reports with lightswitch? this is from online documentation:

http://documentation.devexpress.com/#XtraReports/CustomDocument9901

http://documentation.devexpress.com/#XtraReports/CustomDocument10310

hope it helps!

cheers!

Kivito

lorenzo77vr on Sun, 28 Aug 2011 15:51:35


Hi Kivito,

thank you for reply..

I already check these tutorials but i need something as this:

http://www.paulspatterson.com/technology/lightswitch/microsoft-lightswitch-%E2%80%93-using-devexpress-xtrareports-for-parameterized-reporting/

But, in the latest version of xtraReports, I got an error with ReportPreview.Show.

I spent many days about this error, checking this thread, but none reply to me "how to.." .

I realized that ReportPreview.Show is now obsolete, but my goal is the same explained by Paul Patterson!

I wrote to Devexpress support center but nothing.. 

(Sorry for my english)

Lorenzo



Lorenzo

Kivito on Sun, 28 Aug 2011 16:04:42


hi!

yes, reportpreview.show is obsolete in newer version, i believe that his article was made with 11.1.5, you should get latest (11.1.7) cause it have many fixes, and then you can create screen with report which accept parameters, just do rightclick on screens tree in project explorer, choose "add screen", and you can create screen with reportpreview control on it (you will see it on list in add screen wizard, probably as latest item something like reportpreviewscreen), then in code behind for that screen you will see similar code from this post and that is your starting point.. hope it helps!

Kivito

MarkA Howell on Sun, 28 Aug 2011 21:53:37


Hi Dave,

Wow...Thanks!

I was also experiencing the inconsistency you described.  I felt like I had to "prime the pump" running each report several times before I got data.

I made the change you suggest by commenting out the model.CreateDocument line and NICE!  Data everytime.

 

Thanks for the tip!

Mark

Faizal Shaji - Codemills on Thu, 15 Sep 2011 09:44:22


A parameter window is waiting with a submit button to click.How to get the result without pressing submit button.

 

Is there way to print without showing the report in screen.that is printing on a single click without showing preview.

AzHaddad64 on Thu, 29 Mar 2012 12:08:28


If you want to hide the report parameters "submit" button, go to its data source, and set the visible property to false as below:

eMCeee89 on Tue, 09 Apr 2013 13:04:07


Hey,

i know how to silently pass parameter to DevExpress Xtra Report by modifying "CustomizeReportPreviewModel" method like this:

    Public Sub CustomizeReportPreviewModel(model As DevExpress.Xpf.Printing.ReportPreviewModel)
      model.Parameters("Parameter1").Value = Me.Parameter
    End Sub

I would like to know if there is a way how to refresh/update report showed in the screen after changing Me.Parameter value.

Because if I change Me.Parameter value, report does nothing, i think i need to refresh or reload report, but Me.Parameter is value assigned by selecting item on the screen where report is, so I can not refresh whole screen.

If there is a way, please let me know :)

Thank you

PaulPerret on Tue, 03 Dec 2013 16:27:12


eMCeee89, I'm also having same issue you were having back in April, have you found a solution to display the report after programmatically assigning a value without having to press "Submit"?  Thanks