Hi there
Could you please help me to make this code work?
I'm trying to make use of sub report and filter it in the below code as it printing
using System.Collections;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Reports.Win;
using DevExpress.ExpressApp.Reports;
using DevExpress.ExpressApp.Filtering;
using DevExpress.Data.Filtering;
using DevExpress.XtraReports.UI;
using System.Drawing;
using AAAA.Module.Custom;
using AAAA.Module.Data;
private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
XRSubreport subreport = sender as XRSubreport;
TestLine line = subreport.Report.GetCurrentRow() as TestLine ;
ReportData reportdata = line.Session.FindObject<CustomReportData>(new BinaryOperator("Name", "SYS0001"));
XafReport report = reportdata.LoadXtraReport(Application.CreateObjectSpace()); ///We don't have Application.CreateObjectSpace());
report.SetFilteringObject(new LocalizedCriteriaWrapper(report.DataType, new OperandProperty("Oid") == line.Oid));
subreport.ReportSource = report;
}
to add sub report we do following
public class CustomReportData : ReportData
{
public CustomReportData(Session session) : base(session) { }
protected override XafReport CreateReport()
{
XafReport report = base.CreateReport();
report.DesignerLoaded += new DevExpress.XtraReports.UserDesigner.DesignerLoadedEventHandler(report_DesignerLoaded);
return report;
}
void report_DesignerLoaded(object sender, DevExpress.XtraReports.UserDesigner.DesignerLoadedEventArgs e)
{
IToolboxService ts = (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));
ts.AddToolboxItem(new ToolboxItem(typeof(XRBarCustomGraph)));
ts.AddToolboxItem(new ToolboxItem(typeof(XRSubreport)));
}
}
Best regards,
Duc Hong Doan
Hello Duc,
Thanks for contacting us. Fact is that in XAF we do not support the sub reports feature, and we specially disabled it to prevent our users from using it (Reports - A disabled XRSubreport feature is available in the reports designer's Toolbox)
However, if you still want to use it, I suggest you replace the Application.CreateObjectSpace line with the following code: new ObjectSpace(new UnitOfWork( line.Session.DataLayer), XafTypesInfo.Instance)
Thanks,
Dennis
P.S.
Duc, can we make the questions you send us by email Public, so that other Support Center users could learn from them?
Fantastic,
Thank you , you saved my day.
ps: the subreport features can not be replaced with inherited report.
Hello Duc,
Thanks for the feedback. We also have a suggestion to support subreports in XAF: Reports.Subreports - Support subreport functionality.
What about publishing your questions in the Support Center?
Thanks,
Dennis
thank you so much for the hint.
Appreciate your help!
What about publishing your questions in the Support Center?
Sure. Please go ahead.
Thanks, Duc!