The Master-Detail Report article in the XtraReports documentation describes how to create master-detail reports in two ways - via the DetailReportBand and XRSubreport controls. The first approach is preferable and can be easily used in XAF. However, if you need to use the second approach, steps required to implement it in XAF should be slightly modified, because generally the class on the Many side of an association does not have a simple property with the master's ID. You can filter a detail report by the master object's ID:
[C#]usingDevExpress.ExpressApp.Reports;privatevoidsubreport1_BeforePrint(objectsender,System.Drawing.Printing.PrintEventArgse){XRSubreportsubreport=(XRSubreport)sender;subreport.ReportSource.Parameters["MasterID"].Value=((XafReport)xafReport1).ObjectSpace.GetKeyValue(GetCurrentRow());}
For additional information, please see reports in the attached example.
Note, this example is now included as a part of the FeatureCenter demo.
IMPORTANT NOTES
If you use the ViewDataSource (from the ReportsV2 module) for the master report, then you will have to modify your script as follows:
[C#]usingDevExpress.Xpo;privatevoidsubreport2_BeforePrint(objectsender,System.Drawing.Printing.PrintEventArgse){XRSubreportsubreport=(XRSubreport)sender;subreport.ReportSource.Parameters["MasterID"].Value=((ViewRecord)GetCurrentRow())["Oid"];}
Question Comments
Added By: zhan gao at: 5/23/2012 12:11:04 AM
The example dosen't support 11.2?
Added By: Anatol (DevExpress Support) at: 6/5/2012 4:17:31 AMThe example was updated and now works fine with version 11.2.
Added By: Willem de Vries at: 10/24/2012 8:22:38 AMThank you for providing this example.
Whilst the first approach may be preferable for simple reports, i find this example indispensable for creating reports with detail-reports anywhere in the report. The first approach does not give the possibility to continue the master report after the details (e.g. for a section where a customer can sign the contract).
Looks like this is broken/Changed for 12.2. I have to change existing subreports based on this sample to set Request Parameters to False, because after updating the dialog shows up. Even if I do that, the Parameters Dialog is shwoing...
Added By: Anatol (DevExpress Support) at: 4/2/2013 7:28:52 AMIt is required to make the parameter invisible to hide the parameters panel. I apologize for missing this step. I have updated the example.
Added By: Paolo Parente at: 1/31/2014 12:46:25 AMHi, this example doesn't works for me. Maybe the problem should be that the ID type is GUID? What type the parameter should be if the ID type is GUID? Thanks, Paolo
Added By: Alexander Dračka at: 11/4/2014 5:58:41 AMI'm currently dealing with the very same issue. What a system type should be used to make Guid applicable in this scenario?