ReportBook with empty report

7 posts, 1 answers
  1. perico
    perico avatar
    28 posts
    Member since:
    Dec 2006

    Posted 25 Sep 2017 Link to this post

    Hi,
    Is there a way to remove empty reports from a ReportBook ?

    Thank you

     

    Before R1 of telerik reporting, I was doing something like this :

     

    If Not TryCast(myRptBook.Reports(4), ReportLibrary1.Report1) Is Nothing Then : If Not DirectCast(myRptBook.Reports(4), ReportLibrary1.Report1).haveData Then myRptBook.Reports.Remove(myRptBook.Reports(4))
    End If

    With 

    Private Sub detail_ItemDataBound(sender As Object, e As EventArgs) Handles detail.ItemDataBound
        Me.haveData = True
    End Sub
  2. Yana
    Admin
    Yana avatar
    4907 posts

    Posted 28 Sep 2017 Link to this post

    Hello Pierre,

    The provided snippets seems correct and I will need some more information on the exact scenario you have in order to test the case - could you let me know what errors you're experiencing with R1 release? What was the version you had before the upgrade? Do you use ItemDataBound event for all the data items in the report?

    I'm looking forward to your reply.

    Regards,
    Yana
    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
  3. perico
    perico avatar
    28 posts
    Member since:
    Dec 2006

    Posted 29 Sep 2017 Link to this post

    Hello Yana,

    my problem is that since R1, it's not recomanded to use reportbook.report.

    API Changes: ReportBook
    The property Telerik.Reporting.ReportBook.Reports is now obsolete. Please use Telerik.Reporting.ReportBook.ReportSources property instead.
    The property Telerik.Reporting.ReportBook.ReportParameters is now obsolete. Please use Telerik.Reporting.ReportBook.Parameters property instead.
    The property Telerik.Reporting.ReportBook.PageSettings is now obsolete. Please use Telerik.Reporting.Report.PageSettings property instead.

     

    So my question is : is it possible to delete empty reports in a reportbook using reportsources property instead of reports ?

     

    Thank you

  4. Yana
    Admin
    Yana avatar
    4907 posts

    Posted 04 Oct 2017 Link to this post

    Hello Pierre,

    Please excuse me for missing this.  Indeed, with R1 release the Reports collection property is replaced by ReportSources property. So, in your case, you could use InstanceReportSource to add the reports to the ReportBook and after that you could easily get a reference to each report and check its haveData value through its ReportDocument property.

    I hope this will be helpful.

    Regards,
    Yana
    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
  5. perico
    perico avatar
    28 posts
    Member since:
    Dec 2006

    Posted 12 Apr 2018 Link to this post

    Hello Yana,

    Can you give me a quick sample please ?

    Thank you

  6. Answer
    Silviya
    Admin
    Silviya avatar
    414 posts

    Posted 17 Apr 2018 Link to this post

    Hello Pierre,

    There are three steps for adding a report to a ReportBook using InstanceReportSource:
    - create a separate InstanceReportSource for each report;
    - assign its ReportDocument property to an instance of the corresponding report;
    - add all InstanceReportSources to the ReportBook ReportSources property.
    Public Class ReportBook1
        Inherits ReportBook
     
        Public Sub New()
            Dim mainRpt = New InstanceReportSource()
            mainRpt.ReportDocument = New MainReport()
            Me.ReportSources.Add(mainRpt)
            Dim rpt = New InstanceReportSource()
            rpt.ReportDocument = New Report1()
            Me.ReportSources.Add(rpt)
        End Sub
    End Class
    It is important to add Reports wrapped in InstanceReportSources, so that afterwards they could be cast to it.
    InstanceReportSource.ReportDocument is an instance of a report, hence could be cast to the particular report type that has the custom hasData property.

    To remove the reports where hasData is False from the ReportBook you can get reference to each report source as InstanceReportSource and assign that reference ReportDocument to a report which has the hasData property (in the snippet below represented by the ReportWithHasData class)
    For Each rptsrc In (Collection copy of Me.ReportSources here)
        Dim instanceReport = TryCast(rptsrc, InstanceReportSource)
        Dim reportTest As ReportWithHasData = TryCast(instanceReport.ReportDocument, ReportWithHasData)
        If Not reportTest.hasData Then
            'remove report from report book
        End If
    Next

    In case the issue still persist, please open a new support ticket with attached sample with your current settings in order to investigate further.

    Regards,
    Silviya
    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
  7. perico
    perico avatar
    28 posts
    Member since:
    Dec 2006

    Posted 26 Apr 2018 Link to this post

    Thank you Silviya problem solved
Back to Top