【问题标题】:How to load devexpress xtrareport from file and connect data如何从文件加载 devexpress xtrareport 并连接数据
【发布时间】:2016-03-31 17:34:25
【问题描述】:

我在我的项目中将 devexpress xtrareports v.15 用于 winforms。

我有发票报告。它里面有一些文本字段和一个列表。我将数据连接到报告 ctor 中的源:

public InvoiceReport(InvoiceCommonData icd, List<ReportPosition> positions)
    {            
        InitializeComponent();            
        this.ReportCommonDataSource.DataSource = icd;
        this.positionsList.DataSource = positions;            
    }

当我打印在 Visual Studio 中创建的报表时,数据以正确的方式连接。 但我需要为此报告加载不同的布局。我将报告布局存储为 repx 文件并尝试在运行时从文件中加载它:

InvoiceReport report = new InvoiceReport(model.GetCommonData(), model.GetPositions());
var filename = "D://InvoiceReport.repx";
report.LoadLayout(filename);

当我打印报告时,我看到普通数据 (icd) 已绑定并已打印,但列表 (positions) 未绑定,它是空表而不是真实数据。 问题是如何从文件加载 xtrareport 布局并保存所有数据连接?

【问题讨论】:

    标签: devexpress xtrareport


    【解决方案1】:

    但我认为您可以尝试将默认 repx 文件的连接替换到您的主连接,因为当我们从报告设计器创建 repx 文件时,我们设置连接,并且当我们尝试使用查看器文件预览报告时,repx 保存为默认值获取默认值保存连接,所以尝试从所需的 sql 连接替换连接。

    点赞if (((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters != null) //change if connection exists in report { ((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters = null; } ((DevExpress.DataAccess.Sql.SqlDataSource)devxReport.DataSource).ConnectionParameters = new DevExpress.DataAccess.ConnectionParameters.CustomStringConnectionParameters(sqlConnectionString);

    【讨论】:

    • Lalit Sharma 感谢您的回答。我的问题是,当我从文件报告中加载布局时,不显示 List。当我不加载布局时,它可以正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多