如何使用reportviewer正确绑定对象?

| 我最近一直在研究报表查看器,但有一个我无法解决的问题... 我正在尝试从对象(标头)的集合中绑定数据,其中每个对象都具有子对象(行)的集合。如何才能做到这一点?以下是我当前拥有的代码(somedata是标头对象的集合)。 具有ReportViewer控件的Windows窗体具有以下内容:
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.LoadReportDefinition(GetReport());
reportViewer1.LocalReport.DataSources.Clear();
var dataSourcesNames = GetDataSourceNames();
var headerSource = new ReportDataSource(dataSourcesNames[0], somedata);
reportViewer1.LocalReport.DataSources.Add(headerSource);
reportViewer1.RefreshReport();
标头对象:
public class ReportHeader{
    readonly string id;
    readonly List<ReportRow> rows;

    public ReportData(Header h) {
        this.id = h.Id;
        rows = new List<ReportRow>();
        foreach(RowObject o in h.Rows){
            rows.Add(new ReportRow(o));
        }
    }

    public string Id { get { return id; } }
    public List<ReportRow> Rows { get { return rows;} }
}
行对象:
public class ReportRow{
    readonly decimal sum;
    readonly string type;
    readonly string code;

    public ReportDataRow(RowObject r) {
        sum = r.Sum;
        type = r.Type;
        code = r.Code;
    }

    public decimal Sum { get { return sum; } }
    public string Type { get { return type; } }
    public string Code { get { return code; } }
}
我创建了一个报表,该报表具有ReportHeader的所有属性以及一个应包含所有ReportRows的列表,但它似乎不起作用。唯一的解决方案是制作两个单独的集合,即ReportHeader集合和ReportRow集合,然后分别绑定它们,如下所示:
var headerSource = new ReportDataSource(dataSourcesNames[0], somedata);
reportViewer1.LocalReport.DataSources.Add(headerSource);
var rowSource = new ReportDataSource(dataSourcesNames[1], somedata.Rows);
reportViewer1.LocalReport.DataSources.Add(rowSource);
使用此解决方案,我需要在集合之间建立某种关系。所以请帮忙。 (请注意,我为问题简化了很多对象)
已邀请:
如果我正确理解您的问题。您能否只传递一个布尔对象isHeader,然后在.rdlc文本框中的可见性中执行一个= Fields!isHeader.value的函数。如果所有字段都正确分层和隐藏,则可以在同一列中包含标题和数据。

要回复问题请先登录注册