作成したオブジェクトをレポートに接続し、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();
}
人のデータを含むレポートを読み込む代わりに、レポート ビューアーは際限なく読み込みます。
私は何が間違っているのですか?
ありがとう