John Smith
John Smith

Reputation: 1793

connecting SyncFusion ReportViewer to an object

I created a simple sample project where I try to connect created object to a report and view it via a SyncFusion ReportViewer.

Main Window of the app looks like this:

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

then I have created the Person class, which I want to be displayed in a collection in the report. It looks like this:

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

Then I have created a .rdlc report file and created a dataset called PersonDataSet which is using object datasource targeting Person class.

In the report theres a table with items from the PersonDataSet - name and age.

In Loaded event function of the main window of the app Im trying to create a list of Persons and pass it to the report:

 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();
        }

Instead of loading the report with persons data, the report viewer is endlessly loading..

any idea what am I doing wrong?

thanks

Upvotes: 1

Views: 1307

Answers (1)

John Smith
John Smith

Reputation: 1793

After several hours of searching I finally solved it out. just replace the window onload method with:

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();

Obviously the processingMode have to be set.

Upvotes: 1

Related Questions