Crystal Reports クリスタルレポートへコンボボックスから値を渡す
フォームにコンボボックスとCrystalReportViewerコントロールを配置して
そこにコンボボックスで選択したデータをレポートに表示する。
と、なるはずなのになぜかパラメーターの入力ダイアログが表示されてしまっていた。
// Create a CrResults object CrResults myReport = new CrResults(); // Set the ParameterValue of the report string g = cmb_g_id.SelectedValue.ToString(); myReport.SetParameterValue("g_id", g); // Set the DataSource of the report myReport.SetDataSource(ds); // Set the Report Source to ReportView CrvResults.ReportSource = myReport;
どうしてかな〜と、解決策を探していると...
知識のごみ箱 クリスタルレポートに表示する値を渡す
を発見!
そこに注意することとして
「なお、これはdatasetからデータをセットした後に記入すること
データセット前に行うと表示されない。」
と、書いてある!
そのとおりにdatasetからデータをセットした後にSetParameterValueすることで
あっさり解決してしまいました。
// Create a CrResults object CrResults myReport = new CrResults(); // Set the ParameterValue of the report string g = cmb_g_id.SelectedValue.ToString(); // Set the DataSource of the report myReport.SetDataSource(ds); myReport.SetParameterValue("g_id", g); // Set the Report Source to ReportView CrvResults.ReportSource = myReport;
mezashiさん、ありがとうございました!