Link to home
Start Free TrialLog in
Avatar of RayFrangie
RayFrangie

asked on

CR10 / VB.NET : RefreshReport Keeps Asking for Parameter Entry

Hi All,

I've created a custom toolbar for the Report Viewer and having difficulty with the RefreshReport option always asking to enter the parameters required for the report.

When i first load the report, it doesn't ask because i have added the values as discreet values, code as follows:

... ... ...
            ' Set Discreet value to the entered integer
            pdvStockLessThan.Value = txtLowStockVariable.Text

            ' Add Discreet Value to Value Collection
            pvCollection.Add(pdvStockLessThan)

            ' Apply Value Automatically to Report
            rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)

            ' Clear Collection and prepare for next parameter if any
            pvCollection.Clear()

            ' Set the report source for the crystal reports
            ' viewer to the report instance.
            ReportViewer.ReportSource = rptLowStock

            ' Zoom viewer to fit to the whole page so the user can see the report
            ReportViewer.Zoom(100)

            ' Get Report Page Count
            PageCount = rptLowStock.FormatEngine.GetLastPageNumber(New CrystalDecisions.Shared.ReportPageRequestContext)
... ... ...

Report Loads fine with the correct value as stated in the text box's default entry.

The problem here is that when i click on the Refresh button which in turn calls the RefreshReport sub, it pops up asking to enter the parameter which in this case, is the StockLevel Parameter

The following is the code that i've currently got for the refresh button (which i have tried multiple commands with the code to try and solve this) but to no avail.

Current Refresh Button Code:

    Private Sub tbnShowRefresh_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbnShowRefresh.Activate
        ' Clear Collection and prepare for next parameter if any
        pvCollection.Clear()

        ' Set Discreet value to the entered integer
        pdvStockLessThan.Value = txtLowStockVariable.Text

        ' Add Discreet Value to Value Collection
        pvCollection.Add(pdvStockLessThan)

        ' Apply Value Automatically to Report
        rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)

        ReportViewer.ReportSource = rptLowStock
        ReportViewer.RefreshReport()
        UpdatePageNumber()
    End Sub

No matter what i try it keeps asking for the parameters... I cant seem to find something that'll help me avoid this

Anyone out there got an answer for me?

Many thanks in Advance

Ray.
Avatar of ebolek
ebolek

o. why dont you hold the values when the user first enters it, and then put the same code to the
refresh reprort event,

 Set Discreet value to the entered integer
        pdvStockLessThan.Value = txtLowStockVariable.Text

        ' Add Discreet Value to Value Collection
        pvCollection.Add(pdvStockLessThan)

        ' Apply Value Automatically to Report
        rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)
This wioll automatically set the values again, and wont ask you the prompt box.This is the nature of crystal reports. Hold the valuies and set them back gaain in the refresh event

Regards
Emre
Avatar of RayFrangie

ASKER

Hi ebolek,

The value in the textbox will be changed by the user at runtime, and on clicking the refresh button, i need it to refresh the report with the new parameters.

Unless i'm doing something wrong (which is where i need your help :-) ) it keeps popping up with the Enter Parameter Values Dialog Box.

Hope this adds more light at the end of the tunnel

Thanks in advance

Ray.
that is fine. Put the same code in the refresh event but dont clear the values collection. Restore the values that user enters to the text box and then set the values to it.
ebolek,

Just tried your advice... same thing

Here's the code of the updated refresh event, maybe this will help:

    Private Sub tbnShowRefresh_Activate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbnShowRefresh.Activate
        ' Set Discreet value to the entered integer
        pdvStockLessThan.Value = txtLowStockVariable.Text

        ' Add Discreet Value to Value Collection
        pvCollection.Add(pdvStockLessThan)

        ' Apply Value Automatically to Report
        rptLowStock.DataDefinition.ParameterFields("StockLevel").ApplyCurrentValues(pvCollection)

        ReportViewer.ReportSource = rptLowStock
        ReportViewer.RefreshReport()
        UpdatePageNumber()
    End Sub


Thanks in Advance.

Ray.
Ray,

Is the refresh button being clicked the one on the crystal viewer or is it your own form button?

frodoman
Frodo,

Its my own one.... (The crystal toolbar looks like crap so i brought it to life a little :P ) The code in the above post is the code for the Refresh Button.

I'm using the RefreshReport Command to refresh the report.



Ray.
Ray,

Unfortunately as far as I know there's no simple way to do what you want.  I've been involved in some previous discussions and that's been the result every time (example: https://www.experts-exchange.com/questions/20944952/Crystal-Report-With-Parameter-Automatic-Refresh.html ).

The only way I've heard of someone working around this is to have their own refresh button fire off a process that saves the current parameter values, closes the form containing the CR viewer, then opens a new instance of the form and kicks off the "new report" process.  Basically instead of refreshing you completely close the report and start over with the saved parameter values.  Of course this assumes that you're using a subform for your viewer and it isn't in your application's main form.

This isn't a great solution of course, but it's the only one that I've heard of being used successfully.  

Good luck,

frodoman
Avatar of Mike McCracken
I agree with frodoman.  The RefreshReportCommand is set to delete the parameters and prompt for new ones.

mlmcc
Hi Guys,

I was looking into it last night and had a look at the members for the CrystalReportViewer as seen here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrfwindowsformscrystalreportviewermemberstopic.asp

It seems like there's a ReportRefresh Event which should fire when the report is refreshed (Which in theory should fire when the CrystalReportViewer.RefreshReport. command is used). Any one tried using this event to do what i'm after? I havent tried it yet, i will later on though...

Any info is more than welcome

Many thanks

Ray.
ASKER CERTIFIED SOLUTION
Avatar of EwaldL
EwaldL

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EwaldL,

Perfect... Exactly what i wanted...

Loads the report perfectly, does not ask for a parameter, you hit the nail on the head. 500 Points to you.

Many thanks to all, hope you all learnt something new just like i did

Once again, many thanks

Regards,

Ray.
nice one, good to hear it's working for you now! :-)
the problem with EwaldL's solution (which is what i did first) is that assigning a new reportsource to a viewer seems to tear down the whole widget and spawn a new on (behind the scenes, watch with your debugger)... ie: its painfully slow and has some nasty flash as it destroys the existing widget.  whereas if you use the viewers refresh button/method, its much quicker and slicker.  i have 6 charts embeded in my app, and hence the slowness is multiplied by 6, so i really need to find a way to set the parameter in the current existing report in the viewer... any hope?