Link to home
Start Free TrialLog in
Avatar of g_johnson
g_johnsonFlag for United States of America

asked on

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.
Avatar of star_trek
star_trek

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
Avatar of g_johnson

ASKER

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.

Avatar of Mike McCracken
Do you have a report object?

mlmcc
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.
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

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