How to: Set parameters on a Crystal Report
It is possible to add parameters to reports. Using these parameters you can allow users to set date ranges, or pass other information to a report. Using the following method, you can set the parameters:
/// <summary>
/// Set value for report parameters
/// </summary>
/// <param name="name">Parameter name.</param>
/// <param name="value">Value to be set for the specified parameter.</param>
public void SetParameter(string name, object value)
{ //Access the specified parameter from the parameters collection
CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition parameter = _reportDocument.DataDefinition.ParameterFields[name];
// Now get the current value for the parameter and clear them
CrystalDecisions.Shared.ParameterValues currentValues = parameter.CurrentValues;
currentValues.Clear();
// Create a value object for Crystal reports and assign the specified value.
CrystalDecisions.Shared.ParameterDiscreteValue newValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
newValue.Value = value;
// Now add the new value to the values collection and apply the
// collection to the report.
currentValues.Add(newValue);
parameter.ApplyCurrentValues(currentValues);
}