我有一个简单的类(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 报告向导-> 然后这个对话打开:
我选择对象绑定(bind)。然后我选择我的报告类,然后选择检索数据源架构。(我尝试了两者,但没有成功)
然后我创建一个表单。添加一个文档查看器。然后在我的 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();
}
我运行我的程序,但没有可见数据。我刚刚收到此错误:
我更改报表类以继承我在报表中使用的数据源接口(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; }
}
这次错误消失了,但没有数据可见。
如何创建绑定(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/