c# - 如何使用 devExpress ReportWizard 创建报表并将其绑定(bind)到对象

标签 c# reporting-services crystal-reports devexpress

我有一个简单的类(class)。我想用这个类创建一个报告。这是我的课:

public class report
{
    public string userName { get; set; }
    public string userVardNo { get; set; }
    public string userMobile { get; set; }
    public string userBirthDay { get; set; }
    public int totalHours { get; set; }
    public int totalMinutes { get; set; }
    public int totalDays { get; set; }
    public string monthName { get; set; }
    public string reportDateTime { get; set; }
    public string totalPrice { get; set; }
    public string pricePerHour { get; set; }
}

这就是我一步步创建报告的方法:

项目->添加新项目->DevExpress v X.X 报告向导-> 然后这个对话打开: enter image description here

我选择数据绑定(bind)报告。然后 : enter image description here

我选择对象绑定(bind)。然后我选择我的报告类,然后选择检索数据源架构。(我尝试了两者,但没有成功)

enter image description here

然后我选择所有字段等等。一切都好。我设计我的报告并关闭它。 enter image description here

然后我创建一个表单。添加一个文档查看器。然后在我的 Form 构造函数类中编写这些行:

public report_form()
    {
        InitializeComponent();
        report report_class = new report();
        report_class.userName = "Soup MacTavish";report_class.userMobile = "555-987654";//And so on...
        XtraReport1 report_1 = new XtraReport1();
        report_1.DataSource = report_class;
        documentViewer1.DocumentSource = report_1;
        documentViewer1.Refresh();
    }

我运行我的程序,但没有可见数据。我刚刚收到此错误:

enter image description here

我更改报表类以继承我在报表中使用的数据源接口(interface),如下所示:

public class report: DevExpress.DataAccess.ObjectBinding.ObjectDataSource
{
    public string userName { get; set; }
    public string userVardNo { get; set; }
    public string userMobile { get; set; }
    public string userBirthDay { get; set; }
    public int totalHours { get; set; }
    public int totalMinutes { get; set; }
    public int totalDays { get; set; }
    public string monthName { get; set; }
    public string reportDateTime { get; set; }
    public string totalPrice { get; set; }
    public string pricePerHour { get; set; }
}

这次错误消失了,但没有数据可见。

enter image description here

如何创建绑定(bind)到类的报告?

最佳答案

首先,我建议您使用 Microsoft Styleguide。所以写Classnames Uppercase (Report)等等 Microsoft C# Codeconventions .

但是现在你的问题来了。据我所知你必须使用列表。 BindingList、ReadOnlyCollection 等也可以工作,但让我们简单一点。 尝试以下数据绑定(bind)代码:

List<Report> dummyList = new List<Report>();
dummyList.Add(new Report());
XtraReport myReport = new XtraReport();
myReport.DataSource = dummyList;

这应该适合你。您的类不需要实现任何接口(interface)。

关于c# - 如何使用 devExpress ReportWizard 创建报表并将其绑定(bind)到对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38418657/

相关文章:

c# - 如何在 C# 中将 12 位整数转换为十六进制字符串?

c# - log4net 性能 : should i check log level before trying to log?

reporting-services - SSRS中的无人参与执行帐户

sql-server - 将 SQL Report Server 处理卸载到专用服务器 - 值得吗?

visual-studio-2010 - 如何以编程方式将 Crystal Reports 子报表导入 Visual Studio 2010 中的报表部分

sql - 如何在 Crystal 报表中使用多个存储过程?

c# - 在不知道谁是父级的情况下从父级中删除 View

c# - 具有多种类型的 Entity Framework (代码优先)设计思维

reporting-services - SQL Server 报告服务 2008 : How to remove hyperlink in excel export?

c# - ID 的 Crystal 报表