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

Testing for empty sub-reports

9 Answers 242 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 07 Jul 2010, 08:00 PM
I have a master report, the details section of which contains 3-subreports; "Payroll", "O&M Labor" and "Capital Labor". If one of the subreports contains no data, it is not printed, which I expect. In the 2nd screenshot, the "Payroll" subreport doesn't print because there are no rows. However, the space allocated for the subreport is blank, dropping the "O&M Labor" subreport down about .25". I need a way to test if a subreport is empy, and relocate the subsequent reports accordingly. Compare the 2-screenshots and you can see what I mean.

Thanks

It looks like all I need to do is set the .Visible property of the empty sub-report to False, and that takes care of blank space. The subsequent sub-reports reposition themselves. But I'm still trying to figure out if the sub-report is empty.

9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 08 Jul 2010, 03:20 PM
Hi Patrick,

Check the following blog post for more info on your inquiry and let us know if further help is needed.

Greetings,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Patrick
Top achievements
Rank 1
answered on 08 Jul 2010, 03:54 PM
Here's the code for the event handler:

private void payrollSubreport1_ItemDataBound(object sender, EventArgs e)
{
  Debugger.Break();
  Telerik.Reporting.Processing.SubReport subReport = (Telerik.Reporting.Processing.SubReport)sender;
  Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)subReport.InnerReport;
  subReport.Visible = report.ChildElements.Find("detail", true).Length > 0;
}

And here's the exception that's getting thrown when the bold line in the code snippet executes:

System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'Telerik.Reporting.Processing.Report' to type 'Telerik.Reporting.Processing.SubReport'."
Source="ETLReportsLibrary"
StackTrace:
     at ETLReportsLibrary.BudgetComparativeMasterReport.payrollSubreport1_ItemDataBound(Object sender, EventArgs e) in C:\ETLReportsLibrary\ETLReportsLibrary\BudgetComparativeMasterReport.cs:line 69
     at Telerik.Reporting.ReportItemBase.RaiseEvent(Object key, Object sender, EventArgs e)
     at Telerik.Reporting.ReportItemBase.RaiseItemDataBound(Object sender, EventArgs e)
     at Telerik.Reporting.Processing.ReportItemBase.Process(DataMember data)
InnerException:

BTW, I'm using Q2 2009 version.
0
Steve
Telerik team
answered on 08 Jul 2010, 05:20 PM
Hello Patrick,

By the cast error you receive, I would assume that payrollSubreport1 is your actual report used as subreport, while you should hook up to the ItemDataBound event of the SubReport item itself.
This is clearly visible by the second line from the code snippet which "drills-down" to the actual report.

Kind regards,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Patrick
Top achievements
Rank 1
answered on 08 Jul 2010, 07:22 PM
I'm wiring up the .ItemDataBound() event handler for the payroll sub-report in the master report constructor:

this.payrollSubreport1.ItemDataBound += new EventHandler(payrollSubreport1_ItemDataBound);

and yes, payrollSubreport1 is an instance of the sub-report. I've modified the handler like so, and have stepped thru in the debugger and see where .Visible property is getting set correctly, but I'm still seeing the space where the sub-report should appear had it not been empty.

private void payrollSubreport1_ItemDataBound(object sender, EventArgs e)
{
  Telerik.Reporting.Processing.Report subReport = (Telerik.Reporting.Processing.Report)sender;
  subReport.Visible = subReport.ChildElements.Find("detail", true).Length > 0;
}
0
Patrick
Top achievements
Rank 1
answered on 09 Jul 2010, 02:48 PM
*bump*
0
Steve
Telerik team
answered on 09 Jul 2010, 05:16 PM
Hi Patrick,

Do you have other report items that are on the same X location as the subreport you're hiding by any chance i.e. on its right? If this is the case, the subreport would be hidden but items below it would not move up due to the fact that there is another item with the same X location. This is how the item positioning logic works in Telerik Reporting.
If this is not the case, please provide us with a screenshot (prior/after) or a sample runnable project and we would advise you accordingly.

Best wishes,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Patrick
Top achievements
Rank 1
answered on 09 Jul 2010, 06:08 PM
The Location.X properties of the sub-reports are all zero, but they are stacked, not side by side. See attachments.

Thanks
0
Patrick
Top achievements
Rank 1
answered on 12 Jul 2010, 04:22 PM
*bump*

I've attached a screenshot of the report with the Payroll sub-report .Visible property set to false in the designer. You can see that the space allocated to the sub-report is now completely occupied by the O&M Labor sub-report, which I expect. Evidently this is not happening when the property is programmically set to false in the payrollSubreport1_ItemDataBound() event handler.
0
Steve
Telerik team
answered on 13 Jul 2010, 03:24 PM
Hi Patrick,

It is not clearly visible from your report where the space is coming from, as both your main report and subreports have transparent background color. Looking at the WithPayrollsubreport screenshot, there is a white space between it and the next "O & M Labor" report, which looks like the same amount left after payroll has been hidden. Generally the best way to pinpoint such things is if you apply a more contrasting background colors while testing, so you can locate the problem areas.
Another thing to try is to set the height of the subreport to a very small size at runtime i.e.

public Report1()
        {
            InitializeComponent();
            payrollSubreport1.Height = new Telerik.Reporting.Drawing.Unit(1, UnitType.Mm);
        }

Kind regards,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Patrick
Top achievements
Rank 1
Answers by
Steve
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or