Back to Devexpress

ParameterCollection Class

corelibraries-devexpress-dot-xtrareports-dot-parameters-7b3ce7ee.md

latest5.5 KB
Original Source

ParameterCollection Class

Represents a collection of Parameter objects.

Namespace : DevExpress.XtraReports.Parameters

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
[ListBindable(BindableSupport.No)]
public class ParameterCollection :
    Collection<Parameter>,
    IEnumerable<IParameter>,
    IEnumerable
vb
<ListBindable(BindableSupport.No)>
Public Class ParameterCollection
    Inherits Collection(Of Parameter)
    Implements IEnumerable(Of IParameter),
               IEnumerable

The following members return ParameterCollection objects:

Remarks

This collection is returned via the XtraReport.Parameters property. See Using Report Parameters to learn more.

Example

This example demonstrates how to create a report with a parameter at runtime.

After a parameter is added to the report, its value can be used in the report’s XtraReportBase.FilterString, or displayed in a XRLabel control.

Then, when the report is being previewed, an end-user can modify the parameter’s value via the Parameters UI, which is enabled using the ReportPrintTool.AutoShowParametersPanel property.

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Parameters;
// ...

private void simpleButton1_Click(object sender, EventArgs e) {
    // Create a report instance.
    XtraReport1 report = new XtraReport1();

    // Create a parameter and specify its name.
    Parameter param1 = new Parameter();
    param1.Name = "CatID";

    // Specify other parameter properties.
    param1.Type = typeof(System.Int32);
    param1.Value = 1;
    param1.Description = "Category: ";
    param1.Visible = true;

    // Add the parameter to the report.
    report.Parameters.Add(param1);

    // Specify the report's filter string.
    report.FilterString = "[CategoryID] = [Parameters.CatID]";

    // Force the report creation without previously 
    // requesting the parameter value from end-users.
    report.RequestParameters = false;

    // Show the parameter's value on a Report Header band.
    XRLabel label = new XRLabel();
    label.DataBindings.Add(new XRBinding(param1, "Text", "Category: {0}"));
    ReportHeaderBand reportHeader = new ReportHeaderBand();
    reportHeader.Controls.Add(label);
    report.Bands.Add(reportHeader);

    // Assign the report to a ReportPrintTool,
    // to hide the Parameters panel,
    // and show the report's print preview.
    ReportPrintTool pt = new ReportPrintTool(report);
    pt.AutoShowParametersPanel = true;
    pt.ShowPreviewDialog();
}
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Parameters
' ...

Private Sub simpleButton1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles simpleButton1.Click
    ' Create a report instance.
    Dim report As New XtraReport1()

    ' Create a parameter and specify its name.
    Dim param1 As New Parameter()
    param1.Name = "CatID"

    ' Specify other parameter properties.
    param1.Type = GetType(System.Int32)
    param1.Value = 1
    param1.Description = "Category: "
    param1.Visible = True

    ' Add the parameter to the report.
    report.Parameters.Add(param1)

    ' Specify the report's filter string.
    report.FilterString = "[CategoryID] = [Parameters.CatID]"

    ' Force the report creation without previously 
    ' requesting the parameter value from end-users.
    report.RequestParameters = False

    ' Show the parameter's value on a Report Header band.
    Dim label As New XRLabel()
    label.DataBindings.Add(New XRBinding(param1, "Text", "Category: {0}"))
    Dim reportHeader As New ReportHeaderBand()
    reportHeader.Controls.Add(label)
    report.Bands.Add(reportHeader)

    ' Assign the report to a ReportPrintTool,
    ' to hide the Parameters panel,
    ' and show the report's print preview.
    Dim pt As New ReportPrintTool(report)
    pt.AutoShowParametersPanel = True
    pt.ShowPreviewDialog()
End Sub

Inheritance

Object Collection<Parameter> ParameterCollection

See Also

ParameterCollection Members

Use Report Parameters

DevExpress.XtraReports.Parameters Namespace