2012-01-16 63 views
2

LocalReportオブジェクトを処理する方法はありますか(この部分を完了しました)、別のフォームのReportViewerコントロールの後に表示されますか?このアイデアはReportViewerなしで印刷することです(すでに完了しています)。ただし、ユーザーが印刷しようとしているものをプレビューすることもできます。Visual Studio LocalReportオブジェクトとReportViewer

私はVisual Basic .NET SDK 3.5とVisual Studio 2008を使用しています。必要に応じて2010年も使用できます。 ...

この上の任意のヒント

ReportViewer1.LocalReport = myLocalReport 

が、運のない

ReportViewerLocalReportプロパティは読み取り専用であるため、:

私はこのような何かをしようと試みましたか?前もって感謝します。

(私はReportViewer1.LocalReportメソッドを使用して、このプリフォームするために知っている。私が欲しいのは、単一のコードを作成し、直接またはプレビューフォームにプリンタにのいずれかに結合することがある)

答えて

0

LocalReportは読み取り専用ですが、ReportPathとReportEmbeddedResourceが設定可能なある

はこのような何かを試してみてください、またはあなたのレポートがLocalReport

reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("GravatomsReportRegister", GravatomsFullInfoByIdBindingSource)); 
      reportViewer1.LocalReport.ReportEmbeddedResource = "Gravatun.GraviGrancumReport.rdlc"; 
      reportViewer1.RefreshReport(); 
0

のReportPathプロパティを設定しようと埋め込まれていない場合、私はあなたに似たような状況を持っている私は、レコード生成できるサービスを持っていました。 eaローカルレポートをPDF、電子メールなどに生成することができます。しかし、ReportViewer.LocalReportは読み取り専用のプロパティなので、レポートを作成するためのコードを複製するか、LocalReportからReportViewerに値をコピーする必要があります.LocalReport。私はどちらかのオプションのファンではありません。何かがコピーされない(サブレポートイベント)か、コードの重複があるためです。

私は、ReportViewerでLocalReportをリフレクションして設定する次の拡張を思いついた。私はこれを十分にテストしておらず、悪い考えかもしれません!しかし、それは私が現在取り組んでいるプロジェクトのために働くようです。 ReportViewerがローカルレポートを追加して初期化するかどうかはわかりません。

私はあなたの責任においてこのエンフォースを使用することはできません - わかりやすい説明はしないでください

LocalReport localReport = reportService.GenerateCurrentOrdersReport(....); 
reportViewer.SetLocalReport(localReport); 
:THIS

public static class ReportViewerExtensions 
{ 
    public static void SetLocalReport(this ReportViewer reportViewer, LocalReport report) 
    { 
     var currentReportProperty = reportViewer.GetType().GetProperty("CurrentReport", BindingFlags.NonPublic | BindingFlags.Instance); 
     if (currentReportProperty != null) 
     { 
      var currentReport = currentReportProperty.GetValue(reportViewer, null); 
      var localReportField = currentReport.GetType().GetField("m_localReport", BindingFlags.NonPublic | BindingFlags.Instance); 
      if (localReportField != null) 
      { 
       localReportField.SetValue(currentReport, report); 
      } 
     } 
     reportViewer.RefreshReport(); 
    } 
} 

使い方をDO

関連する問題