如何使用 devExpress ReportWizard 创建报表并将其绑定到对象
How to create a report and bound it to an object using devExpress ReportWizard
我有一个简单的class。我想用这个 class 创建一个报告。这是我的 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报表向导->
然后这个对话打开:
我选择数据绑定报表。然后 :
我选择对象绑定。然后我选择我的报告 class 然后选择检索数据源模式。(我都试过了但没有成功)
然后我选择所有字段等等。一切都好。我设计我的报告并关闭它。
然后我创建一个表单。向其添加文档查看器。然后在我的表单构造函数中 class 我写了这些行:
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();
}
i 运行 我的程序但是没有数据可见。我刚收到这个错误:
我更改我的报告 class 以继承我在报告中使用的数据源接口,如下所示:
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; }
}
这次错误消失了,但没有数据可见。
如何创建绑定到 class 的报告?
首先,我建议您使用 Microsoft Styleguide。所以写Classnames Uppercase (Report) 等等
Microsoft C# Codeconventions
.
但是现在解决你的问题。据我所知你必须使用一个列表。 BindingList、ReadOnlyCollection 等也可以工作,但让我们简单点。
尝试使用以下数据绑定代码:
List<Report> dummyList = new List<Report>();
dummyList.Add(new Report());
XtraReport myReport = new XtraReport();
myReport.DataSource = dummyList;
这应该适合你。您的 class 不需要实现任何接口。
我有一个简单的class。我想用这个 class 创建一个报告。这是我的 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报表向导->
然后这个对话打开:
我选择数据绑定报表。然后 :
我选择对象绑定。然后我选择我的报告 class 然后选择检索数据源模式。(我都试过了但没有成功)
然后我选择所有字段等等。一切都好。我设计我的报告并关闭它。
然后我创建一个表单。向其添加文档查看器。然后在我的表单构造函数中 class 我写了这些行:
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();
}
i 运行 我的程序但是没有数据可见。我刚收到这个错误:
我更改我的报告 class 以继承我在报告中使用的数据源接口,如下所示:
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; }
}
这次错误消失了,但没有数据可见。
如何创建绑定到 class 的报告?
首先,我建议您使用 Microsoft Styleguide。所以写Classnames Uppercase (Report) 等等 Microsoft C# Codeconventions .
但是现在解决你的问题。据我所知你必须使用一个列表。 BindingList、ReadOnlyCollection 等也可以工作,但让我们简单点。 尝试使用以下数据绑定代码:
List<Report> dummyList = new List<Report>();
dummyList.Add(new Report());
XtraReport myReport = new XtraReport();
myReport.DataSource = dummyList;
这应该适合你。您的 class 不需要实现任何接口。