Hello Dave,
We've discussed this task with one of our customers in an private issue, and there are two solutions for this problem:
[C#]public class ViewController1 : ViewController {
public ViewController1() { }
protected override void OnActivated() {
base.OnActivated();
Frame.GetController<WinReportServiceController>().CustomShowPreview += new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview);
}
void ViewController1_CustomShowPreview(object sender, CustomShowPreviewEventArgs e) {
e.Report.FilterString = CriteriaOperator.Parse("Owner.Oid=?", SecuritySystem.CurrentUserId).ToString();
}
protected override void OnDeactivating() {
base.OnDeactivating();
Frame.GetController<WinReportServiceController>().CustomShowPreview -= new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview);
}
}
2. Otherwise, the simplest way is to set the required filter via the XtraReport.FilterString property, and hide this property from the Properties grid, as shown in the following code:[C#]public class ViewController1 : ViewController {
public ViewController1() { }
protected override void OnActivated() {
base.OnActivated();
XtraReport.FilterControlProperties += new FilterControlPropertiesEventHandler(XtraReport_FilterControlProperties);
Frame.GetController<WinReportServiceController>().CustomShowPreview += new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview);
Frame.GetController<WinReportServiceController>().CustomShowDesignForm += new EventHandler<CustomShowDesignFormEventArgs>(ViewController1_CustomShowDesignForm);
}
void XtraReport_FilterControlProperties(object sender, FilterControlPropertiesEventArgs e) {
if (e.Control is XtraReport) {
e.Properties.Remove("FilterString");
}
}
void ViewController1_CustomShowDesignForm(object sender, CustomShowDesignFormEventArgs e) {
e.Report.FilterString = CriteriaOperator.Parse("Owner.Oid=?", SecuritySystem.CurrentUserId).ToString();
}
void ViewController1_CustomShowPreview(object sender, CustomShowPreviewEventArgs e) {
e.Report.FilterString = CriteriaOperator.Parse("Owner.Oid=?", SecuritySystem.CurrentUserId).ToString();
}
protected override void OnDeactivating() {
base.OnDeactivating();
Frame.GetController<WinReportServiceController>().CustomShowPreview -= new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview);
Frame.GetController<WinReportServiceController>().CustomShowDesignForm -= new EventHandler<CustomShowDesignFormEventArgs>(ViewController1_CustomShowDesignForm);
}
}
In this case end-users will be able to filter the report via the Filtering object.
Does any of these solutions meet your requirements?
Thanks,
Anatol
-
Anatol,
Some code has changed, could you help me?
this code: Frame.GetController<WinReportServiceController>()
Error 88 The type 'DevExpress.ExpressApp.Reports.Win.WinReportServiceController' cannot be used as type parameter 'ControllerType' in the generic type or method 'DevExpress.ExpressApp.Frame.GetController<ControllerType>()'. There is no implicit reference conversion from 'DevExpress.ExpressApp.Reports.Win.WinReportServiceController' to 'DevExpress.ExpressApp.Controller'.
The WinReportServiceController class should be convertible to Controller, and it should be possible to pass it to the Frame.GetController method. It is unclear why this functionality does not work in your project. Please ensure that the class name passed to the GetController method references a class from our assembly, and a class with the same name and namespace is not defined in your project. If this does not help, please provide a sample project reproducing the problem.