New to Telerik Reporting? Download free 30-day trial

Adding the Windows Forms Report Viewer Control to a Windows Forms .NET Project

This article explains the steps needed to integrate the WinForms report viewer into .NET 6 and higher projects.

The WinForms Report Viewer can display reports generated by an Embedded Reporting engine, Telerik Reporting REST Service, or Telerik Report Server. The setup described in this article is valid for all service types unless a particular service is specified. In this case, the corresponding step or option is valid only for the specified service types.

Prerequisites:

  • Visual Studio 2019 or newer
  • .NET SDK 6 or newer
  • Windows Forms App (.NET 6+) project

Steps to add report viewer to a Windows Forms .NET 6 and higher project

  1. Add the following assembly references (available in the Telerik Reporting installation Bin directory) or NuGet package references (available in Telerik private NuGet repository):

    • Telerik.Reporting
    • Telerik.ReportViewer.WinForms
    • Telerik.Reporting.Services.HttpClient (Required only when the viewer is used with REST Service or Report Server)

    The Telerik.Reporting and Telerik.Reporting.Services.HttpClient assemblies are located in the folder %programfiles(x86)%\Progress\Telerik Reporting 2024 Q4\Bin\netstandard2.0. The Telerik.ReportViewer.WinForms assembly can be found in %programfiles(x86)%\Progress\Telerik Reporting 2024 Q4\Bin. Select the net6.0-windows or net8.0-windows subfolder depending on the exact framework used. We recommend using NuGet packages. In this case, the Telerik.ReportViewer.WinForms package will add Telerik.Reporting and all its dependencies automatically. If you prefer to add the Telerik Reporting assemblies as references, you need to add also all the Telerik.Reporting dependencies manually. This includes but may not be limited to the following packages:

    • Microsoft.Extensions.Configuration
    • Microsoft.Extensions.Configuration.Json
    • Microsoft.Extensions.Configuration.Binder
    • SQLitePCLRaw.bundle_green

    If you need to add also the external dependencies of Telerik.Reporting as assembly references, it would be necessary to include all their dependencies manually.

  2. Instantiate UriReportSource and set the proper UriReportSource.Uri relative path:

    • When using an Embedded Reporting engine: Reference a descriptive report definition (TRDP or TRDX report) from a local folder, or type report definition (CS or VB report) from a report library project. For example, add a new folder named Reports in the application main folder, copy your TRDP reports there, and reference one of them. Don't forget to set their property 'Copy to Output Directory' to 'Copy always' or 'Copy if newer':

      Telerik.Reporting.UriReportSource reportSource1 = new Telerik.Reporting.UriReportSource();
      reportSource1.Uri = @"Reports\MyReportName.trdp";
      reportSource1.Parameters.Add("Parameter1_Name", "Parameter1_Value");
      reportSource1.Parameters.Add("Parameter2_Name", "Parameter2_Value");
      

      The report will be rendered with the values "Parameter1_Value" and "Parameter2_Value" for the Report Parameters named "Parameter1_Name" and "Parameter2_Name", correspondingly.

    • When using a Telerik Reporting REST Service: The reports get rendered server-side and need to be accessible by the service. For that reason, you need to reference a descriptive report definition (TRDP or TRDX report) from a folder accessible by the service, or type report definition (CS or VB report) from a report library project that is accessible by the service.

      Telerik.Reporting.UriReportSource reportSource1 = new Telerik.Reporting.UriReportSource();
      reportSource1.Uri = @"MyReportName.trdp";
      reportSource1.Parameters.Add("Parameter1_Name", "Parameter1_Value");
      

      With the above setting, the REST Service will look for the report named "MyReportName.trdp" in the folder specified as an argument of the UriReportSourceResolver constructor. The report will be rendered with the value "Parameter1_Value" for the Report Parameter named "Parameter1_Name".

    • When using a Telerik Report Server : The reports will be rendered by the Report Server. For that reason, you need to reference a descriptive report definition (TRDP or TRDX report) that is hosted on the server

      Telerik.Reporting.UriReportSource reportSource1 = new Telerik.Reporting.UriReportSource();
      reportSource1.Uri = @"MyCategory/MyReportName.trdp";
      reportSource1.Parameters.Add("Parameter1_Name", "Parameter1_Value");
      

      With the above setting, the Report Server will look for the report named "MyReportName.trdp" in the category "MyCategory". The report will be rendered with the value "Parameter1_Value" for the Report Parameter named "Parameter1_Name".

  3. Instantiate and set the WinForms Report Viewer:

    • When using an Embedded Reporting engine :

      var reportViewer = new Telerik.ReportViewer.WinForms.ReportViewer();
      reportViewer.ReportSource = reportSource1;
      reportViewer.Dock = System.Windows.Forms.DockStyle.Fill;
      reportViewer.Name = "reportViewer1";
      reportViewer.TabIndex = 1;
      reportViewer.RefreshReport();
      

      Don't forget to add the viewer to the Form's Controls.

    • When using a Telerik Reporting REST Service :

      var reportViewer = new Telerik.ReportViewer.WinForms.ReportViewer();
      reportViewer.ReportSource = reportSource1;
      reportViewer.Dock = System.Windows.Forms.DockStyle.Fill;
      reportViewer.Name = "reportViewer1";
      reportViewer.TabIndex = 1;
      reportViewer.ReportEngineConnection = "engine=RestService;uri=http://localhost:59654/api/reports;timeout=100;keepClientAlive=True";
      reportViewer.RefreshReport();
      

      The above settings assume that the REST Service is running on http://localhost:59654/api/reports and the client will not expire if not active.

    • When using a Telerik Report Server :

      var reportViewer = new Telerik.ReportViewer.WinForms.ReportViewer();
      reportViewer.ReportSource = reportSource1;
      reportViewer.Dock = System.Windows.Forms.DockStyle.Fill;
      reportViewer.Name = "reportViewer1";
      reportViewer.TabIndex = 1;
      reportViewer.ReportEngineConnection = "engine=ReportServer;uri=http://yourreportserver:83/;username=yourusername;password=yourpassword";
      reportViewer.RefreshReport();
      

      The above settings assume that the Report Server is running on http://yourreportserver:83. Note that you need to provide a valid username and password so that the viewer can log in successfully, or have the guest user enabled in the Report Server.

See Also

In this article