Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用devExpress ReportWizard创建报告并将其绑定到对象_C#_Reporting Services_Crystal Reports_Devexpress - Fatal编程技术网

C# 如何使用devExpress ReportWizard创建报告并将其绑定到对象

C# 如何使用devExpress ReportWizard创建报告并将其绑定到对象,c#,reporting-services,crystal-reports,devexpress,C#,Reporting Services,Crystal Reports,Devexpress,我有一节简单的课。我想用这个类创建一个报表。这是我的班级: 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

我有一节简单的课。我想用这个类创建一个报表。这是我的班级:

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 constructor类中,我写了以下几行:

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; }
}
此时间错误消失,但没有可见数据


如何创建绑定到类的报表?

首先,我建议您使用Microsoft Styleguide。所以写类名大写(Report)等等

但现在来谈谈你的问题。据我所知,你必须使用列表。BindingList、ReadOnlyCollection等也可以使用,但让我们简化一下。 尝试以下代码进行数据绑定:

List<Report> dummyList = new List<Report>();
dummyList.Add(new Report());
XtraReport myReport = new XtraReport();
myReport.DataSource = dummyList;
List dummyList=new List();
添加(新报告());
XtraReport myReport=新的XtraReport();
myReport.DataSource=dummyList;
这应该对你有用。您的类不需要实现任何接口