[]
Sets values for the parameters of the currently displayed report in the Viewer.
public void SetParametersValues(IEnumerable<IParameter> parameters)
Type | Name | Description |
---|---|---|
IEnumerable<IParameter> | parameters | A collection of IParameter objects representing the parameters of the report and their respective values to be set. |
This method allows for dynamic modification of report parameters at runtime. By providing a collection of IParameter objects, you can adjust the data or the appearance of the report based on user input, application state, or other criteria. It's important to ensure that the names of the parameters provided match exactly with those defined in the report. Mismatched parameter names will not be recognized by the report and, as a result, will not affect the report's output.
public class ParameterAdapter : IParameter
{
private string _name;
private IEnumerable<object> _values;
public ParameterAdapter(string name, IEnumerable< object> values)
{
_name = name;
_values = values ?? throw new ArgumentNullException(nameof(values), "Values cannot be null.");
}
public string Name
{
get => _name;
set => _name = value ?? throw new ArgumentNullException(nameof(value), "Name cannot be null.");
}
public IEnumerable<object> Values
{
get => _values;
set => _values = value ?? throw new ArgumentNullException(nameof(value), "Values cannot be null.");
}
}
// Handler for a UI control event, e.g., a button click
private void OnUpdateReportParametersClick(object sender, EventArgs e)
{
// Assuming 'viewer' is an instance of the Viewer class
// Assuming 'startDatePicker' and 'regionComboBox' are UI controls
// Cast each element of the array to object
var startDateParameter = new ParameterAdapter("StartDate", new[] { startDatePicker.Value }.Cast <object>());
// For the region parameter, ensure that the selected item is treated as an object.
// If regionComboBox.SelectedItem is not null, cast it to object; otherwise, handle the null case appropriately.
var regionParameterValues = regionComboBox.SelectedItem != null ? new[] { regionComboBox.SelectedItem }.Cast<object>()
: Enumerable.Empty <object>();
var regionParameter = new ParameterAdapter("Region", regionParameterValues);
var parameters = new List<IParameter> { startDateParameter, regionParameter };
// Dynamically update the report with new parameters
viewer.SetParametersValues(parameters);
}