Hello,
I am working on a report where i have a sub report ,
i implemented the NeedDataSource event of the SubReport object inside the main report,
Also i set the ReportSource property to object instance of my Sub report.
The sub report is displayed correctly (for example setting "=Fields.Name" in a text box returns the right value)
I need to access to the DataSource property inside the sub report from C# (this.dataSource) bu it is always null.
Thanks in Advance
Amine
I am working on a report where i have a sub report ,
i implemented the NeedDataSource event of the SubReport object inside the main report,
Also i set the ReportSource property to object instance of my Sub report.
The sub report is displayed correctly (for example setting "=Fields.Name" in a text box returns the right value)
I need to access to the DataSource property inside the sub report from C# (this.dataSource) bu it is always null.
Thanks in Advance
Amine
4 Answers, 1 is accepted
0

Amine
Top achievements
Rank 1
answered on 16 Mar 2015, 07:52 AM
Finally , i found a sollution.
the current object is under : subReportItem.DataObject.RawData
the current object is under : subReportItem.DataObject.RawData
0
Hello Amine,
If you need to bind the sub report to the same data as the master report, please use the approach discussed in How to bind the DataSource of a SubReport in the designer.
We will appreciate it if you elaborate on the scenario and reason to access the sub report's DataSource in code.
Regards,
Stef
Telerik
If you need to bind the sub report to the same data as the master report, please use the approach discussed in How to bind the DataSource of a SubReport in the designer.
We will appreciate it if you elaborate on the scenario and reason to access the sub report's DataSource in code.
Regards,
Stef
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0

Amine
Top achievements
Rank 1
answered on 17 Mar 2015, 09:27 AM
Hello Stef, Thanks for the reply.
Actually this is not exactly my scenario. However i found a solution as i posted before. but this is the complete scenario :
I have a main report (MainReport) containing a subreport(FirstSubReport) witch also conatins a subreport(SecondSubReport)
in the main report i added a subreport and implemented its needsDataSource event :
Then inside the firstSubreport i added a sub report object for the Second one and tried to implement the needsDataSource as i did for the first one:
so my problem was that this.DataSource was null and The solution was to use subReportItem.DataObject.RawData instead:
And it worked as expected..
Regards
Amine
Actually this is not exactly my scenario. However i found a solution as i posted before. but this is the complete scenario :
I have a main report (MainReport) containing a subreport(FirstSubReport) witch also conatins a subreport(SecondSubReport)
in the main report i added a subreport and implemented its needsDataSource event :
private
void
FirstSubReport_NeedDataSource(
object
sender, EventArgs e)
{
Telerik.Reporting.Processing.SubReport subReportItem = sender
as
Telerik.Reporting.Processing.SubReport;
subReportItem.InnerReport.DataSource = ((MyBusinessObject)
this
.DataSource).FirstCollection;
}
Then inside the firstSubreport i added a sub report object for the Second one and tried to implement the needsDataSource as i did for the first one:
private
void
SecondSubReport_NeedDataSource(
object
sender, EventArgs e)
{
Telerik.Reporting.Processing.SubReport subReportItem = sender
as
Telerik.Reporting.Processing.SubReport; subReportItem.InnerReport.DataSource = ((FirstObject)
this
.DataSource).SecondCollection;
}
so my problem was that this.DataSource was null and The solution was to use subReportItem.DataObject.RawData instead:
private
void
SecondSubReport_NeedDataSource(
object
sender, EventArgs e)
{
Telerik.Reporting.Processing.SubReport subReportItem = sender
as
Telerik.Reporting.Processing.SubReport;
subReportItem.InnerReport.DataSource = ((FirstObject)subReportItem.DataObject.RawData).SecondCollection;
}
And it worked as expected..
Regards
Amine
0
Hello Amine,
What you have found out is correct and is also described in the Understanding Events help article:
"The sender parameter of the event handler methods is in fact the processing report item...
Be very careful when working inside event handlers. If by mistake you modify the report item (the private field of the report class, i.e. this.textBox1) instead of its processing counterpart (the sender argument), all subsequent processing items will be modeled after the modified reporting item."
The text above means that it is not correct to use this.DataSource inside events. You should always get a reference to the desired report item from the sender argument.
Regards,
Nasko
Telerik
What you have found out is correct and is also described in the Understanding Events help article:
"The sender parameter of the event handler methods is in fact the processing report item...
Be very careful when working inside event handlers. If by mistake you modify the report item (the private field of the report class, i.e. this.textBox1) instead of its processing counterpart (the sender argument), all subsequent processing items will be modeled after the modified reporting item."
The text above means that it is not correct to use this.DataSource inside events. You should always get a reference to the desired report item from the sender argument.
Regards,
Nasko
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.