私は実際にアプリでこれを実行しました。ただし、どのパラメータを渡すか心配するのではなく、自分のレポートクラスのConstructorオブジェクトをスーパーオーバーロードするのではなく、それは私が扱っているオブジェクトとして "ReportViewer"のインスタンスを持っています。
public partial class MyReport : Form
{
protected ReportViewer reportViewer = new ReportViewer();
public MyReport()
{ InitializeComponent(); }
その後、私はいくつかのパブリックメソッド、必要に応じて異なるパラメータを必要とする各レポートの1を公開しますが、一般的なビーイングは、レポートのためにその中の1つまたは複数のテーブルで設定されたデータを渡された場合。私は、テーブルを通じて動的サイクルとは...実際にこれを呼び出し、すべて一緒にそれを置くために、レポートビューアーコントロール
public Boolean GenerateCommonReport(DataSet oDS,
String NameOfReport, String[] SubReports)
{
// Set Processing Mode.
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.LoadReportDefinition(GetRDLC(NameOfReport));
// I've actually an extended version that includes subreports with an array
// of separate .RDLC file names in case the report is nested... if so, those
// would need to be added too.
if(! (SubReports == null))
{
// the hitch here, is that in my case, any sub-reports are named by the same
// name as the .RDLC in the report just in case thee's any object renaming
// when you add one sub-report into the main report. Such as when adding
// textboxes, it will create textbox1, textbox2, textbox3, etc... So, you
// may have to wiggle with this some to match the actual name of the sub-report
// object in your main report.
foreach(String ar in SubReports)
reportViewer.LocalReport.LoadSubreportDefinition(ar, GetRDLC(ar));
}
// Next load the dataset into the report before finally showing.
foreach (DataTable oTbl in oDS.Tables)
// likewise with the datasets. If you look at your RDLC of the schema's
// used, it will reference an outer Dataset name, then force an "_" before
// the actual table it uses WITHIN that dataset. Don't worry, internally
// it splits it up and finds correct correlation.
reportViewer.LocalReport.DataSources.Add(
new ReportDataSource(oDS.DataSetName + "_" + oTbl.TableName, oTbl));
// Finally, add the report viewer control to your displaying form control
reportViewer.Dock = DockStyle.Fill;
this.Controls.Add(reportViewer);
reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
reportViewer.RefreshReport();
// This is actually showing your form as a modal dialog window to the user
this.ShowDialog();
}
// get embedded reports directly from this DLL/project
private Stream GetRDLC(String RptRDLC)
{
// Ex: we want the report "FirstReport" within the "MyReports.dll"
// assembly "MyReports.FirstReport.rdlc"
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
"MyReports." + RptRDLC + ".rdlc");
return stream;
}
}今
に
DataSet oDS = YourObject.HoweverYouQueryToGetADataset();
MyReport oRpt = new MyReport();
oRpt.GenerateCommonReport(oDS, "MyFirstReport", null);
Iを追加しますtry/catchなどの他のバリデーションを取り除き、実際のコードから特定のオブジェクト参照を削除しましたが、下のテンプレートはすばらしいジャンプスタートを与えるはずです。
ありがとう...私はあなたの方法は試してみてください... –