我有一个简单的课程。我想用这个类创建一个报告。这是我的班级:
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报告向导 - >
然后这个对话打开:
我选择了对象绑定。然后我选择我的报告类,然后选择检索数据源模式。(我试过两个但是徒劳无功)
然后我选择所有字段,依此类推。一切都好。我设计我的报告并关闭它。
然后我创建一个表单。添加文档查看器。然后在我的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();
}
我运行我的程序,但没有数据可见。我刚收到这个错误:
我更改了我的报告类,以继承我在报告中使用的数据源接口,如下所示:
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; }
}
这次错误消失但没有数据可见。
如何创建绑定到类的报表?
答案 0 :(得分:2)
首先,我建议您使用Microsoft Styleguide。所以写Classnames大写(Report)等等 {{3}}
但现在你的问题。据我所知你必须使用List。 BindingList,ReadOnlyCollection等也可以,但是让它变得简单。 尝试使用以下DataBinding代码:
List<Report> dummyList = new List<Report>();
dummyList.Add(new Report());
XtraReport myReport = new XtraReport();
myReport.DataSource = dummyList;
这对你有用。您的课程不需要实现任何界面。