最近レポートビューアを勉強していますが、解決できない問題が1つあります...
各オブジェクトに子オブジェクト(行)のコレクションがあるオブジェクト(ヘッダー)のコレクションからデータをバインドしようとしています。これはどのように行うことができますか?以下は私が現在持っているコードの一部です(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コレクションの2つの別々のコレクションを作成し、以下のようにそれらを別々にバインドすることでした。
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);
このソリューションでは、コレクション間に何らかの関係を作成する必要があります。だから助けてください。(質問のためにオブジェクトを大幅に簡略化したことに注意してください)