Example E546
Visible to All Users

Reporting for WinForms - Add Parameters to Report at Runtime

This example shows how to create a report parameter, and pass it to a report at runtime.

Report with Parameters

Files to Look At:

Documentation

More Examples

Example Code

ReportParameterExample/Form1.cs(vb)
C#
using System; using DevExpress.XtraReports.Parameters; using DevExpress.XtraReports.UI; namespace ReportParameterExample { public partial class Form1 : DevExpress.XtraEditors.XtraForm { public Form1() { InitializeComponent(); } 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.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Text", "Category: [CategoryName]")); 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(); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.