Trying to attach a list to a report

2 posts, 0 answers
  1. David
    David avatar
    46 posts
    Member since:
    Nov 2011

    Posted 30 Jan Link to this post

        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.

     

     

     

     

     

     

     

     

     

     

     

  2. Todor
    Admin
    Todor avatar
    270 posts

    Posted 04 Feb Link to this post

    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
Back to Top