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

ReportBook with empty report

6 Answers 189 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
perico
Top achievements
Rank 1
Iron
perico asked on 25 Sep 2017, 03:00 PM

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

6 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 28 Sep 2017, 06:40 PM
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
0
perico
Top achievements
Rank 1
Iron
answered on 29 Sep 2017, 07:25 AM

Hello Yana,

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

[quote]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.[/quote]

 

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

 

Thank you

0
Yana
Telerik team
answered on 04 Oct 2017, 10:48 AM
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
0
perico
Top achievements
Rank 1
Iron
answered on 12 Apr 2018, 09:16 AM

Hello Yana,

Can you give me a quick sample please ?

Thank you

0
Accepted
Silviya
Telerik team
answered on 17 Apr 2018, 09:08 AM
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
0
perico
Top achievements
Rank 1
Iron
answered on 26 Apr 2018, 02:12 PM
Thank you Silviya problem solved
Tags
General Discussions
Asked by
perico
Top achievements
Rank 1
Iron
Answers by
Yana
Telerik team
perico
Top achievements
Rank 1
Iron
Silviya
Telerik team
Share this question
or