This is a migrated thread and some comments may be shown as answers.

Trying to attach a list to a report

1 Answer 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 30 Jan 2019, 11:15 AM

    Hi I have a list that comes into the report viewer demo that has 48 items i am passing it two a report view. But when I look at the report viwer it is comming up blank.

public partial class BoxReportBatches : Telerik.Reporting.Report
   {
       private List<BoxReportObject> _list;
       public BoxReportBatches()
       {
           //
           // Required for telerik Reporting designer support
           //
           InitializeComponent();
           //
           // TODO: Add any constructor code after InitializeComponent call
           //
       }
       public BoxReportBatches(List<BoxReportObject> _dataSource)
       {
           _list = _dataSource;
           this.DataSource = _list;
 
 
       }
   }

 

And here is my reportviewer window

private List<BoxReportObject> _list;
      public ReportViewer(List<BoxReportObject> list)
      {
          InitializeComponent();
          _list = list;
      }
 
      private void ReportViewer_Load(object sender, EventArgs e)
      {
 
 
          // var exeFolder = @"\\server02\sage\CustReports";
           //var exeFolder = @"C:\Program Files (x86)\Sage\Sage200\Reporting\";
          //string reportPath = Path.Combine(exeFolder, @"BoxReport.rdlc");
         // Clipboard.SetText(exeFolder);
          BoxReportBatches report1 = new BoxReportBatches(_list);
           // perform additional operations on the report object if needed          
          Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
          instanceReportSource.ReportDocument = report1;
          this.reportViewer1.ReportSource = instanceReportSource;
            
      }

 

My Box Report Class is 

public class BoxReportObject
 {
     public DateTime ProductionPlanWeekStarting { get; set; }
     public DateTime ProductionPlanWeekEnding { get; set; }
     public string BatchNumber { get; set; }
     public string BoxRef { get; set; }
     public string BoxName { get; set; }
     public decimal Qty { get; set; }
 }

 

 

You can also see here the properties of my report viewer.

 

 

 

 

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 04 Feb 2019, 09:19 AM
Hi David,

There are two modifications necessary for the report to be displayed in the viewer :

 1. The report constructor needs to call the Report InitializeComponent method to create the actual report. You should either call it directly in the second constructor or just call the parameterless constructor from the second one :

public BoxReportBatches(List<BoxReportObject> _dataSource)
    : this()
{
    ...
}
 
or
 
public BoxReportBatches(List<BoxReportObject> _dataSource)
{
    InitializeComponent();
    ...
}


 2. The ReportViewer Load method needs to call the RefreshReport method of the viewer after the new ReportSource has been assigned, i.e. :

this.reportViewer1.RefreshReport();


Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or