Hi,
I have a report which contains two subreports in its details section. The subreports are very similar, each having one text field and one currency field in their details sections and a "Total" currency field in their footer sections using the =Sum() function. All of this works perfectly well, but I need to do some arithmetic in the main report footer section and this is where I have been pulling my hair out.
I need to access the values in the textboxes in the subreports footer sections from within the SubReport1_ItemDataBound and SubReport2_ItemDataBound event handlers of the main report so that I can process these values in the main report footer section. I have seen many threads similar to this one but nothing which demonstrates how to retrieve the textbox values from the places above at runtime.
Any help on this would be massively appreciated as I've tried a million approaches over the last two weeks and am thoroughly sick of this problem now.
Thanks,
Craig
I have a report which contains two subreports in its details section. The subreports are very similar, each having one text field and one currency field in their details sections and a "Total" currency field in their footer sections using the =Sum() function. All of this works perfectly well, but I need to do some arithmetic in the main report footer section and this is where I have been pulling my hair out.
I need to access the values in the textboxes in the subreports footer sections from within the SubReport1_ItemDataBound and SubReport2_ItemDataBound event handlers of the main report so that I can process these values in the main report footer section. I have seen many threads similar to this one but nothing which demonstrates how to retrieve the textbox values from the places above at runtime.
Any help on this would be massively appreciated as I've tried a million approaches over the last two weeks and am thoroughly sick of this problem now.
Thanks,
Craig
7 Answers, 1 is accepted
0
Hello Craig,
Peter
the Telerik team
Our suggestion is to access the SubReport's TextBox item from the Master Report's TextBox ItemDataBound event. I have created a sample report to show you how to access the SubReports' Items. Check it out and let us how it goes.
Peter
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

Craig
Top achievements
Rank 1
Iron
answered on 24 Aug 2010, 06:00 AM
Thanks Peter,
Unfortunately I was not able to open the MasterReport in your example so I could not see what you were demonstrating. The MySubReport opened ok, but not the MasterReport. My environment is: VS2005, Telerik 2010 Q2 and VB.NET.
I was able to convert your C# to VB for the textbox ItemDataBound event thus:
Now when I preview my report I get the following error at the location of TextBox28:
An error has occurred while processing TextBox 'TextBox28':
Index was outside the bounds of the array.
This happens with TextBox28 in the master report footer section and the details section - although it makes no sense to have TextBox28 in the footer because each row in the details section will have its own value for TextBox3, so I have a second problem which is to display in the master report footer section the SUM() of a programmatically assigned textbox in the master report details section. Maybe your example report is helpful in this respect, but sadly I cannot see it.
Regards,
Craig
Unfortunately I was not able to open the MasterReport in your example so I could not see what you were demonstrating. The MySubReport opened ok, but not the MasterReport. My environment is: VS2005, Telerik 2010 Q2 and VB.NET.
I was able to convert your C# to VB for the textbox ItemDataBound event thus:
Private
Sub
TextBox28_ItemDataBound(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
TextBox28.ItemDataBound
Dim
procTextBox =
DirectCast
(sender, Telerik.Reporting.Processing.TextBox)
Dim
procSubReport =
DirectCast
(procTextBox.Report.ChildElements.Find(
"SubReport1"
,
True
)(0), Telerik.Reporting.Processing.SubReport)
Dim
procSubReportTextBox =
DirectCast
(procSubReport.InnerReport.ChildElements.Find(
"TextBox3"
,
True
)(0), Telerik.Reporting.Processing.TextBox)
procTextBox.Value = procSubReportTextBox.Value
End
Sub
Now when I preview my report I get the following error at the location of TextBox28:
An error has occurred while processing TextBox 'TextBox28':
Index was outside the bounds of the array.
This happens with TextBox28 in the master report footer section and the details section - although it makes no sense to have TextBox28 in the footer because each row in the details section will have its own value for TextBox3, so I have a second problem which is to display in the master report footer section the SUM() of a programmatically assigned textbox in the master report details section. Maybe your example report is helpful in this respect, but sadly I cannot see it.
Regards,
Craig
0
Hello Craig,
The only reason for the "Index was outside the bounds of the array." error message is if it could not find such item in its collection. As this is a forum thread, it is not mandatory to provide exact details, but it is always helpful to specify product version and preferred language, so there is no need for additional ticket loop.
Additionally we maintain a free Code Converter, which you can always use to convert code if you have found examples in C#.
I have transferred my colleague's example to VB for your convenience and verified it works with no exceptions.
As for your second question, as explained in the Understanding Report Sections help article, the report footer section is to be used to print report totals or other summary information for the entire report. Similar to the Report Header section, you should always use aggregate functions for the databound items that are calculated for the entire report data.
Best wishes,
Steve
the Telerik team
The only reason for the "Index was outside the bounds of the array." error message is if it could not find such item in its collection. As this is a forum thread, it is not mandatory to provide exact details, but it is always helpful to specify product version and preferred language, so there is no need for additional ticket loop.
Additionally we maintain a free Code Converter, which you can always use to convert code if you have found examples in C#.
I have transferred my colleague's example to VB for your convenience and verified it works with no exceptions.
As for your second question, as explained in the Understanding Report Sections help article, the report footer section is to be used to print report totals or other summary information for the entire report. Similar to the Report Header section, you should always use aggregate functions for the databound items that are calculated for the entire report data.
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

Craig
Top achievements
Rank 1
Iron
answered on 30 Aug 2010, 05:57 PM
Thanks for the VB sample Steve. It works for a static value in TextBox1.Value in the subreport, but when I add data and use an aggregate function such as: = Sum(Fields.MyField) as the value of TextBox1, it stops working and the main report displays nothing for the aggregate field.
As for the second problem, I understand the anatomy of the report surface, it is similar to other reporting technologies I've used to do the same thing successfully for the last 15 years. I think I need to write a user function because the value I want to Sum() in the main report is not in the list of Fields presented in the Edit Expression dialog, but I don't know yet. There's no point in me resolving this part of my problem before I have a solution to the first part.
Regards,
Craig
As for the second problem, I understand the anatomy of the report surface, it is similar to other reporting technologies I've used to do the same thing successfully for the last 15 years. I think I need to write a user function because the value I want to Sum() in the main report is not in the list of Fields presented in the Edit Expression dialog, but I don't know yet. There's no point in me resolving this part of my problem before I have a solution to the first part.
Regards,
Craig
0
Hi Craig,
Peter
the Telerik team
I have attached a modified sample report that is working with data. To avoid further confusion we will appreciate if you modify the attached project to show the difficulties you are experiencing and send it through the support system so we can investigate locally.
Greetings,Peter
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

Keith
Top achievements
Rank 2
answered on 30 Apr 2019, 05:54 PM
This code works great! Thank you for posting. I have wanted to do this for years.
0

Todd
Top achievements
Rank 1
answered on 04 Aug 2020, 01:35 AM
Yes, thank you!