动态设置devexpress报告参数

时间:2016-01-09 17:29:37

标签: c# wpf devexpress

我是devexpress报道的新手。我知道如何设置报告的数据,例如我有以下代码。我可以填充并生成我的报告。参数设计中的问题我可以分配数据源,数据成员,数据显示。但我不知道在报告加载时动态填充参数?

public report1()
{
    InitializeComponent();
    rpt2 rp2 = new rpt2();
    rp2.DataSourceDemanded += rp2_DataSourceDemanded;

    pre1.DocumentSource = rp2;
}
void rp2_DataSourceDemanded(object sender, EventArgs e)
{
    rpt2 report = sender as rpt2 ;
    companyDS ds1 = new companyDS();
    myCon getMyCon1 = new myCon();
    SQLiteConnection con = getMyCon1.GetConnection();
    string sql = "SELECT companyID,companyName from company";
    SQLiteCommand cmd = new SQLiteCommand(sql, con);            
    using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd))
    {
        da.Fill(ds1, "Datatable1");
    }
    report.DataSource = ds1;
    report.DataMember = ds1.DataTable1.TableName;
}

1 个答案:

答案 0 :(得分:0)

我建议你仔细阅读这些示例和文档参考资料。

How to: Create a Report with Parameters (Runtime Sample)
How to add parameters to a report at runtime
Passing a parameter to the report at runtime
how to pass parameter in devexpress report

示例:

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();
}

希望得到这个帮助。