• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2702
  • Last Modified:

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.
0
RayFrangie
Asked:
RayFrangie
  • 5
  • 2
  • 2
  • +3
1 Solution
 
ebolekCommented:
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
0
 
RayFrangieAuthor Commented:
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.
0
 
ebolekCommented:
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.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
RayFrangieAuthor Commented:
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.
0
 
frodomanCommented:
Ray,

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

frodoman
0
 
RayFrangieAuthor Commented:
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.
0
 
frodomanCommented:
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: http://www.experts-exchange.com/Databases/Crystal_Reports/Q_20944952.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
0
 
mlmccCommented:
I agree with frodoman.  The RefreshReportCommand is set to delete the parameters and prompt for new ones.

mlmcc
0
 
RayFrangieAuthor Commented:
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.
0
 
EwaldLCommented:
the behaviour you see with the RefreshReport method is by design.  msdn describes if functionality as follows on
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrfwindowsformscrystalreportviewerclassrefreshreportmethodtopic.asp

"This method will refresh the data for the report currently displayed in the viewer. Any parameters or logon information, needed by the report, will be prompted for."

So instead I would try to refresh the report itself (not the viewer), pass the parameters to it and then pass the report to the viewer.

something like this

rptLowStock.Refresh()
rptLowStock.SetParameterValue("StockLevel", "YourValue")
ReportViewer.ReportSource = rptLowStock
0
 
RayFrangieAuthor Commented:
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.
0
 
EwaldLCommented:
nice one, good to hear it's working for you now! :-)
0
 
joshsteinerCommented:
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?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now