2012-02-08 4 views
1

私はLocalReportオブジェクトを持っていますが、私はすべての適切な情報を記入しています。私はこの同じレポートオブジェクトを使用してさまざまな形式にエクスポートします。私のユーザはImage、Excel、Word、Pdfなどを選択することができ、私はそれらの要求を容易にするために同じレポートオブジェクトを使用します。VS2010 RDLC C#。 LocalReportオブジェクトをReportViewerに設定するにはどうすればよいですか?

私の問題は時にはそれを表示することがあります。私は輸出タイプを開くことができますが、それは私が何をしたいのではないことを知っています。私はReportViewerでそれを見たいと思う。私はReportViewer.LocalReportsプロパティを設定し、私が探しているものを得ることができますが、私はすでにすべてのオブジェクトをReportオブジェクトに設定しています。

質問があります:どのように私は間違っており、行うことができないfollowinを行うのですか?

LocalReport _Report = new LocalReport(); 

//set all my report information 

Microsoft.Reporting.WinForms.ReportViewer _rv = new Microsoft.Reporting.WinForms.ReportViewer(); 

//This is what I'm trying to do 
_rv.LocalReport = _Report; 

答えて

2

現在行っていることの順序を変更してみることができます。

  1. フォームにReportViewerを追加します。 (なぜ私はあなたがコード内でReportViewerを作成しているのか分かりませんが、フォームのコントロールに動的に追加しないと思います)。最初のコード行で行ったように作成する必要はありません。

  2. ReportViewer.RefreshReport()メソッドを呼び出すと、フォーム上のレポートがレンダリングされます。

PS:LocalReportオブジェクトが既にある場合は、そのプロパティをReportViewerのレポートオブジェクトに割り当てる必要があります。

+0

時間の95%は、ユーザーがレポートを表示しませんので、私はそれをこのようにやっています。したがって、ReportViewerは使用できません。ほぼすべてのリクエストに対して_Report.Renderを使用して終了します。 – Jmyster

+0

Renderメソッドはストリームを出力します。特にReportViewerで表示したいと言っていますか? :)それはあなたがそれを望んだ方法でうまくいけばとにかく私はうれしいよ。 –

+0

それは私が望むように動作していません。以前はユーザーがレポートを表示しなかったので、Reportオブジェクトを使用して_Report.Render経由でほとんどの出力をストリーミングしました。ユーザーはレポートを表示できるようになり、レポートビューアに配置する必要があります。 LocalReportオブジェクトを返すコードがたくさんあります。私は単に、LocalReportオブジェクトをどのようにレポートビューアに設定するのですか?あなたは_rv.LocalReport = _Reportのように簡単だと思うでしょうが、そうではありません。これは可能ですか? – Jmyster

0

複数の処理モードでレポートを処理できます。次のコードは、処理モードがローカルであることを示しています。

_RptViewer.ProcessingMode=ProcessingMode.Local; 
// _RptViewer is the name of the Report Viewer Control added to your Page/Form. 

LocalReport objRpt=_RptViewer.LocalReport; 
objRpt.ReportPath=Server.MapPath("YourReportName.rdlc"); 

ReportDataSource rds=new ReportDataSource("DataSourceName",DataSourceObject);  
//"DataSourceName" can be the name of the DataSet you created during designing the Report; 
//and DataSourceObject can be a method that returns a data table or DataTable that is defined in your code above, or any valid object that provides data to the report.* 

objRpt.DataSources.Clear(); 
objRpt.DataSources.Add(rds); 

私は上記のコードサンプルがあなたを助けてくれることを願っています。

0

リフレクションを使用してReportViewerでLocalReportを設定すると、問題が発生する可能性があることに注意してください。私は今これをプロジェクトでやっていますが、うまくいくようです。私の答えはこちらをご覧ください:https://stackoverflow.com/a/14329386/285874

1

あなたのように、私はReportViewerでLocalReportを表示できるようにしたかったのです。

ここで私はこれを達成した方法:

Param_MyLocalReportを[.Renderと]うまく機能しているLocalReportです。 ReportViewer1は、レポートを表示するReportViewerです。この機能は自動的に行われ、データソースとパラメータがコピーされます。

 //**************************** 
     //assign report Path 
     reportViewer1.LocalReport.ReportPath = param_MyLocalReport.ReportPath; 
     //**************************** 

     //**************************** 
     //assign data-sources 
     foreach (ReportDataSource MyDS in param_MyLocalReport.DataSources) 
      reportViewer1.LocalReport.DataSources.Add(MyDS); 
     //**************************** 

     //**************************** 
     //Assign parameters 

     //get a list of actual parameters in the report, with the actual assigned value 
     ReportParameterInfoCollection MyOrigParams = param_MyLocalReport.GetParameters(); //I didn't find simpler way to fetch params... 

     //create a List of parameter [to feed the reportViewer] 
     List<ReportParameter> MyListOfPArams = new List<ReportParameter>(); 

     //for each params found through GetParameters(), add it to the List<> of params 
     for (int i = 0; i < MyOrigParams.Count; i++) 
      MyListOfPArams.Add(new ReportParameter(MyOrigParams[i].Name, MyOrigParams[i].Values[0])); 

     //final assignation of the parameters 
     reportViewer1.LocalReport.SetParameters(MyListOfPArams); 
     //**************************** 


     //show the report 
     reportViewer1.RefreshReport(); 

エルニーニョのように、これはヘルパーの機能でプッシュすることができます。以下のような何か:

Private void Convert_LocalReport_To_ReportViewer(LocalReport Param_MyLocalReport, ReportViewer param_MyReportViewer) 
{ 
...copy the same code here... 
} 
+0

電子メールの添付ファイルや、 'ReportViewer'を作成したり表示したりしない他のインスタンスに対して' LocalReports'を生成する必要があるので、これは私にとって最高の解決策でした。埋め込みリソースとして.rdlcを使用するときに 'ReportPath'がヌルであるため、' ReportEmbeddedResource'も同様に設定することをお勧めします。 'reportViewer1.LocalReport.ReportEmbeddedResource = param_MyLocalReport.ReportEmbeddedResource' – Lithium

関連する問題