How to Create Report (RDLC) in WPF


This article shows how to add a RDLC report in WPF.

Suppose I have been assigned the task of generating a RDLC report in WPF.

That contains ID, Name, City, and Order Amount.

So I will show you how to generate a RDLC report in WPF.

It is very simple; believe me it is very simple. So let's start.

Step 1

Create a WPF project; I named it "MonsterBusinessInc".


Step 2

Add a WPF Button, the click event of this button will show you the report; also add the click event for this button.


private void btnClickMe_Click(object sender, RoutedEventArgs e)




Step 3

Add a class in the project under the Entitles folder named "Customer.cs".

Write the code like below:

namespace MonsterBusinessInc.Entities


    public class Customer


        public int ID { get; set; }

        public string Name { get; set; }

        public string City { get; set; }

        public int OrderAmount { get; set; }




Build the project after doing it.

Step 4

Add an .rdlc file named "CustomerReport.rdlc".


Now we have to add the dataset for this report that will be filled at run time when we display the report; i.e. ID, Name, City etc.


Click the DataSet on the Report Data window and the DataSet Properties window will open. Now we must set the properties.


Set the name to "CustomerDataSet". Now click on the "New" Button; the DataSource Window will open.


Select Object and click the "Next" Button.


Now select the Customer Class under Entities that we created earlier and click the "Finish" button.


Now click on the "OK" button and a DataSet will be added for the Customer.rdlc report.

And you can see it in the Report Data Window.


Now right-click on the blank white area and select the table.


Now you will have a blank table in the surface.

Click in the blank field; set the filed name. You also can edit the header for the field.



Now we have a .rdlc report ready to display records after supplying the datasource.

Step 5

Add a User Control in the "User Control" folder in the project named "ReportViewer.xaml".


This reportViewer user control will contain the RDLC report.

Now add two DLLs as references.

The first one is Microsoft.ReportViewer.WinForms .


The second one is WindowsFormsIntegration.


Now add the following line in your "ReportViewer.xaml":






            <rv:ReportViewer x:Name="reportViewer" RenderingComplete="reportViewer_RenderingComplete" />


Now the file will look like:

<UserControl x:Class="MonsterBusinessInc.User_Control.ReportViewer"







             d:DesignHeight="600" d:DesignWidth="800" Loaded="UserControl_Loaded"


    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">


            <rv:ReportViewer x:Name="reportViewer" RenderingComplete="reportViewer_RenderingComplete" />




On the UserControl_Loaded event write the following code.

We can bind the report with the database table from the SQL Server database but now I have generated a DataTable at run time with the same fields details Customer.cs under the Entities folder.

using System.Data;

using Microsoft.Reporting.WinForms;

namespace MonsterBusinessInc.User_Control


    /// <summary>

    /// Interaction logic for ReportViewer.xaml

    /// </summary>

    public partial class ReportViewer : UserControl


        public ReportViewer()





   private void UserControl_Loaded(object sender, RoutedEventArgs e)


            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn ("ID",typeof(int)));

            dt.Columns.Add(new DataColumn("Name", typeof(string)));

            dt.Columns.Add(new DataColumn("City", typeof(string)));

            dt.Columns.Add(new DataColumn("OrderAmount", typeof(int)));


            DataRow dr = dt.NewRow();

            dr["ID"] = 1;

            dr["Name"] = "CK Nitin";

            dr["City"] = "New York";

            dr["OrderAmount"] = 100;




            ReportDataSource reportDataSource = new ReportDataSource();

            reportDataSource.Name = "CustomerReport"; // Name of the DataSet we set in .rdlc

            reportDataSource.Value = dt;

            reportViewer.LocalReport.ReportPath = "D:\\MonsterBusinessInc \\Report\\CustomerReport.rdlc"; // Path of the rdlc file






private void reportViewer_RenderingComplete(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e)






Step 7

Now add a window named "CustomerReport.xaml".

Write the following XAML for this XAML file:

<Window x:Class="Reporting.CustomerReport"



        Title="CustomerReport" Height="600" Width="300"



        <report:ReportViewer ></report:ReportViewer>





Step 8

Now the last step.

Open the MainWindows.xaml

Write the following code in the button click:

CustomerReport rpt = new CustomerReport();



private void btnClickMe_Click(object sender, RoutedEventArgs e)


            CustomerReport rpt = new CustomerReport();




Now Build the project and run it.

Here is the output.



Up Next
    Ebook Download
    View all
    View all