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
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
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
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
Hello Yana,
Can you give me a quick sample please ?
Thank you
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
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