We help IT Professionals succeed at work.

Crystal Report Viewer in C# VS 2008, passing formulae

My application has a form called frmReport which contains a crystal report viewer object called crvMain.  That form has no methods.

The application also has a form called Form1 and it contains some input fields and a button called "ShowReport"

When the user clicks "Show Report", this code is invoked:

                frmReport f = new frmReport();
                f.crvMain.ReportSource = this._CRPath;
                f.crvMain.SelectionFormula = CrystalSelect;
               
                f.ShowDialog();

this._CRPath is the actual network path to the Crystal Report being called.  CrystalSelect is a string containing a list of order numbers to be used as the seleciton criteria in the Crystal report.

This works fine, and the report shows the correct information.

However, the report has a formula called "ReportUser" and I now need to fill that from this code with Environment.UserName.

How can I do that?  If I can't do that, is there some other method short of a table write/read to accomplish this?

Thanks in advance for your help.
Comment
Watch Question

You can create a parameter field in your report and set the value from your code.

 f.SetParameterValue("ReportUser", Environment.UserName);
CrystalReportViewer1.EnableParameterPrompt = False // this will disable the parameter prompt

Author

Commented:
I'm sorry, but I'm not getting this.  "f" in my code is a form, so f.SetParameterValue is not a valid method.  I also can't find that method on f.crvMain (the viewer).

I cannot find a property for EnableParamterPrompt on the viewer either.

Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Do you have a report object?

mlmcc

Author

Commented:
No, my code is exactly as shown above.  I just have a form with a viewer on it.  I set the viewer's ReportSource to the path of an existing Crystal report, set the selection formula for the viewer, and show the form.

I guess I don't know how to do this with a report object.
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
Commented:
You have to use the report object for those properties or methods to show.

You can also change a formula through the report object.

mlmcc