2

適切な情報をすべて入力するLocalReportオブジェクトがあります。この同じレポート オブジェクトを使用して、さまざまな形式にエクスポートします。ユーザーは画像、Excel、Word、PDF などを選択でき、同じレポート オブジェクトを使用してそれらの要求を容易にします。

私の問題は、時々彼らがそれを見たいと思うかもしれないということです. エクスポートされたタイプを開くことができることはわかっていますが、それは私が望んでいることではありません。で見たいですReportViewer。プロパティを設定して探しているものを取得できることはわかってReportViewer.LocalReportsいますが、Report オブジェクトですべてを既に設定しています。

質問は次のとおりです。間違っていて実行できない次のことをどのように行うのですか?

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;
4

4 に答える 4

2

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

  1. ReportViewer をフォームに追加します。(コードで ReportViewer を作成している理由がわかりません。フォームのコントロールに動的に追加するつもりはないと思います。)

  2. ReportViewer.LocalReport オブジェクトですべてのレポート情報を設定します。コードの最初の行で行ったように作成する必要はありません。

  3. ReportViewer.RefreshReport() メソッドを呼び出して、フォームにレポートを表示します。

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

于 2012-02-09T21:35:42.720 に答える
2

あなたと同じように、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...
}
于 2014-06-09T17:50:39.497 に答える
0

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

于 2013-01-16T18:26:38.947 に答える
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);

上記のコード サンプルがお役に立てば幸いです。

于 2012-02-21T17:38:41.367 に答える