Link to home
Start Free TrialLog in
Avatar of DeonM
DeonM

asked on

C#, Crystal Reports parameter dialog displays randomly

Hi,

I assign Crystal Reports parameter values and the report displays great with no dialog popups, but sometimes the dialog just appears for no reason and I cannot figure out why.
I run a report and it works great, I keep the same parameter values and sometimes change them, but the dialog still only appears randomly.

Please see my code below. This code is only code that is relevant to handling my parameters. I removed any other unnecessary code.

Thanks
public partial class frm_ReportViewer : Form
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument myReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        private const string PARAMETER_REPORT_HEADER = "ReportHeader";

	private void frm_ReportViewer_Load(object sender, EventArgs e)
        {            
        	string reportPath = "";
        	ArrayList arrayListreportheader = new ArrayList();
		reportPath = Application.StartupPath + "\\" + "creport.rpt";
                myReport.Load(reportPath);
                arrayListreportheader.Add("Header text here");

                //SQL query and fill dataset here

                myReport.SetDataSource(mydataset);
		
		crystalReportViewer1.ReportSource = myReport;
                    
	        ParameterFields parameterFields = myReport.ParameterFields;
       		SetReportHeaderParameterField(parameterFields, arrayListreportheader);
	        
         
        }

private void SetReportHeaderParameterField(ParameterFields parameterFields, ArrayList arrayList)
        {            
            ParameterField parameterField = parameterFields[PARAMETER_REPORT_HEADER];
            ParameterValues currentParameterValues = new ParameterValues();

            foreach (object submittedValue in arrayList)
            {
                ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
                parameterDiscreteValue.Value = submittedValue.ToString();
                currentParameterValues.Add(parameterDiscreteValue);
            }

            parameterField.CurrentValues = currentParameterValues;
        }
}

Open in new window

Avatar of Death259
Death259
Flag of United States of America image

What if for the last line in your frm_ReportViewer_Load you refresh the crystal report?
ASKER CERTIFIED SOLUTION
Avatar of DeonM
DeonM

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
That was going to be my next suggestion. I've always run into crystal report parameter problems like the one you are experiencing, and i usually solve it with a refresh somewhere, or mvoing where i change the report source.
Avatar of Mike McCracken
Mike McCracken

If you refresh, Crystal will drop the assigned parameter values and prompt for new values.

DO all parameters get legal values?

I think your idea of moving the reportsource assignment is the answer.

mlmcc