Multi-Value Report Parameters

转自:https://docs.devexpress.com/XtraReports/9998/detailed-guide-to-devexpress-reporting/shape-report-data/use-report-parameters/multi-value-report-parameters

This document describes how to create a multi-value parameter and filter report data by the specified parameter values.

multi-value-parameters-preview 

 

TIP

See Specify Query Parameters for information on how to use multi-value parameters in an SQL query.

#Create a Multi-Value Parameter

Follow these steps to create a multi-value parameter at design time:

  1. Create a report parameter and enable the Allow multiple values option (corresponds to the Parameter.MultiValue property).

    multi-value-parameters-create-parameter

  2. Specify a list of predefined values for the parameter. See the following topics for more information:

To create a multi-value report parameter in code, follow the steps below.

  1. Create a StaticListLookUpSettings or DynamicListLookUpSettings class instance and configure it with a set of predefined parameter values.
  2. Assign the newly created instance to the parameter's ValueSourceSettings property.
  3. Enable the parameter's Parameter.MultiValue property. It allows the parameter to have more than one value.

NOTE

A complete sample project is available at https://github.com/DevExpress-Examples/how-to-assign-multiple-values-to-a-report-parameter-from-a-connected-data-source

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

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

// Specify other parameter properties.
parameter1.Type = typeof(System.Int32);
parameter1.MultiValue = true;
parameter1.Description = "Categories: ";

DynamicListLookUpSettings lookupSettings = new DynamicListLookUpSettings();
lookupSettings.DataSource = report.DataSource;
lookupSettings.DataMember = "Categories";
lookupSettings.DisplayMember = "CategoryName";
lookupSettings.ValueMember = "CategoryId";

parameter1.LookUpSettings = lookupSettings;
parameter1.Visible = true;
parameter1.SelectAllValues = true;

report.FilterString = "CategoryName in (?CategoryIDs)";

#Filter a Report by a Multi-Value Parameter

Use the Is any of operator in the report’s filter string:

parameters-multi-value-filter-string 

 

To filter report data in code, specify the report’s FilterString property.

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Parameters;

// ...
// Create a parameter and specify its name. 
Parameter parameter1 = new Parameter(); 
parameter1.Name = "CategoryIDs"; 
Parameter1.Visible = true; 

//... 
// Filter report data  
report.FilterString = "CategoryName in (?CategoryIDs)";  

The filtered report is displayed after a user specifies parameter values.

parameters-multi-value-filter-report

#Pre-Select Parameter Values

Use one of the following methods to pre-select multiple parameter values when a report is first rendered.

parameters-multi-value-preselect-values

  • Assign an array of values to the Default Value (corresponds to Parameter.Value) property.

    parameters-multi-value-preselect-values-specify

  • Set the Expression property to an expression that evaluates to an array of values. You can use data source fields and other parameters in expressions.

    parameters-multi-value-preselect-values-expression

  • Enable the Select all values property to populate the parameter value with all items from its data source (static or dynamic).

     multi-value-parameters-select-allmulti-value-parameters-select-all

     

TIP

Disable the report's RequestParameters property to avoid the Waiting for parameter values message in Preview and display the report with pre-selected parameter values.

#Optional Multi-Value Parameter

You can leave the parameter unspecified and display all report data. A user optionally chooses parameter values to filter the report.

parameters-multi-value-optional

Do the following to make a multi-value parameter optional.

Configure the parameter as follows:

parameters-multi-value-optional-settings 

 

PropertyValue
Allow null valuetrue
Default ValueNot specified
ExpressionNot specified
Select all valuesfalse

Disable the report's RequestParameters property.

report-requestparameters-disable

Use the following report filter string:

?category Is Null or [Category ID] In (?category)

 parameters-multi-value-empty-valueparameters-multi-value-empty-value

 

TIP

You can also use the filter string shown above to filter report data at the data source level. See the Specify Query Parameters topic for more information.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值