本示例阐明了如何把标准的参数编辑器改变为任一自定义编辑器。

注意,从 v2010 vol 2 版开始,按照参数类型 (Parameter.Type 属性值) 来创建默认的编辑器。

要为参数提供自定义编辑器,则接管 XtraReport.ParametersRequestBeforeShow 事件,并把自定义编辑器指派到参数信息的 ParameterInfo.Editor 属性,其中参数信息被存储在 ParametersRequestEventArgs.ParametersInformation 属性返回的集合中。

CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E390。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

C#CopyCode image复制代码
using System;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Parameters;
// ...

private void XtraReport1_ParametersRequestBeforeShow(object sender, ParametersRequestEventArgs e) {
    CategoriesDataSet dataSet = new CategoriesDataSet();
    CategoriesDataSetTableAdapters.CategoriesTableAdapter adapter = 
        new CategoriesDataSetTableAdapters.CategoriesTableAdapter();
    adapter.Fill(dataSet.Categories);

    foreach (ParameterInfo info in e.ParametersInformation) {
        if (info.Parameter.Name == "parameter1") {
            LookUpEdit lookUpEdit = new LookUpEdit();
            lookUpEdit.Properties.DataSource = dataSet.Categories;
            lookUpEdit.Properties.DisplayMember = "CategoryName";
            lookUpEdit.Properties.ValueMember = "CategoryID";
            lookUpEdit.Properties.Columns.Add(new 
                LookUpColumnInfo("CategoryName", 0, "Category Name"));
            info.Editor = lookUpEdit;
        }
    }
}
Visual BasicCopyCode image复制代码
Imports System
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Parameters
' ...

Private Sub XtraReport1_ParametersRequestBeforeShow(ByVal sender As System.Object, _
ByVal e As ParametersRequestEventArgs) Handles MyBase.ParametersRequestBeforeShow
    Dim DataSet As New CategoriesDataSet()
    Dim Adapter As New CategoriesDataSetTableAdapters.CategoriesTableAdapter()
    Adapter.Fill(DataSet.Categories)

    Dim Info As ParameterInfo

    For Each Info In e.ParametersInformation
        If Info.Parameter.Name = "Parameter1" Then
            Dim LookUpEdit As New LookUpEdit()
            LookUpEdit.Properties.DataSource = DataSet.Categories
            LookUpEdit.Properties.DisplayMember = "CategoryName"
            LookUpEdit.Properties.ValueMember = "CategoryID"
            LookUpEdit.Properties.Columns.Add(New _
                LookUpColumnInfo("CategoryName", 0, "Category Name"))
            Info.Editor = LookUpEdit
        End If
    Next Info
End Sub

Expand image参阅