如何解决如何使用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的函数。如果所有字段都正确分层和隐藏,则可以在同一列中包含标题和数据。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。