1

作成したオブジェクトをレポートに接続し、SyncFusion ReportViewer を介して表示する簡単なサンプル プロジェクトを作成しました。

アプリのメイン ウィンドウは次のようになります。

<Window x:Class="testApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
        Title="MainWindow" Height="350" Width="525" Loaded="OnWindowLoad">
    <Grid>
        <syncfusion:ReportViewer Name="reportViewer1" ReportPath="c:\Pool\test\testApp\testApp\Report1.rdlc"  />
    </Grid>
</Window>

次に、レポートのコレクションに表示する Person クラスを作成しました。次のようになります。

namespace testApp
{
    public class Person
    {
        private string m_name;
        public string Name
        {
            get { return m_name; }
            set { m_name = value; }
        }

        private int m_age;
        public int Age
        {
            get { return m_age; }
            set { m_age = value; } }

        public Person(string name, int age)
        {
            Name = name;
            Age = age;
        }
    }
}

次に、.rdlc レポート ファイルを作成し、Person クラスをターゲットとするオブジェクト データソースを使用する PersonDataSet というデータセットを作成しました。

レポートには、PersonDataSet の項目 (名前と年齢) を含むテーブルがあります。

アプリのメイン ウィンドウの Loaded イベント関数で、個人のリストを作成してレポートに渡そうとしています。

 private void OnWindowLoad(object sender, RoutedEventArgs e)
        {
            var persons = new List<Person>
                              {
                                  new Person("Jan", 25),
                                  new Person("Jana", 24)
                              };

            ReportDataSource source = new ReportDataSource
            {
                Name = "PersonDataSet",
                Value = persons
            };

            reportViewer1.DataSources.Add(source);
            reportViewer1.RefreshReport();
        }

人のデータを含むレポートを読み込む代わりに、レポート ビューアーは際限なく読み込みます。

私は何が間違っているのですか?

ありがとう

4

1 に答える 1

1

数時間の検索の後、最終的に解決しました。ウィンドウの onload メソッドを次のように置き換えるだけです。

reportViewer1.ReportPath = @"C:\Pool\test\ReportViewerTest\ReportViewerTest\Report1.rdlc";
            reportViewer1.ProcessingMode = ProcessingMode.Local;

            List<Person> persons = new List<Person>
                                       {
                                           new Person {Age = 99, Name = "Dedek"},
                                           new Person {Age = 14, Name = "Alois"}
                                       };

            ReportDataSource reportDataSource4 = new ReportDataSource("PersonDataSet", persons);

            reportViewer1.DataSources.Add(reportDataSource4);
            reportViewer1.RefreshReport();

明らかに、処理モードを設定する必要があります。

于 2013-08-08T08:39:51.700 に答える