Lesson 3 - Provide Custom Editors for Report Parameters
- 2 minutes to read
This example shows how you can substitute the standard parameter editors that are auto-created according to the parameter types with your own custom editors.
In this tutorial, we will use a report similar to the one created in the preceding lesson: Lesson 2 - Filter a Report on the Server using LightSwitch Query. This report obtains its parameters from a LightSwitch Query, based on which the customer list can be shown for the specified country.
According to this parameter type, XtraReports creates a text-box editor by default. To make using this parameter more convenient for end-users, you can change this editor to a ComboBoxEdit in the CustomizeParameterEditors event handler of your ReportPreviewModel.
The following code illustrates this approach.
using System.Collections.Generic;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Printing;
// ...
namespace LightSwitchApplication {
public partial class ReportPreviewScreen {
public void CustomizeReportPreviewModel(ReportPreviewModel model) {
model.CustomizeParameterEditors += model_CustomizeParameterEditors;
}
List<object> customers;
void model_CustomizeParameterEditors(object sender, CustomizeParameterEditorsEventArgs e) {
if (e.Parameter.Name == "Country") {
var editor = new ComboBoxEdit();
editor.ItemsSource = customers;
editor.IsTextEditable = false;
e.Editor = editor;
e.BoundDataMember = "EditValue";
}
}
partial void ReportPreviewScreen_Activated() {
this.ReportTypeName = "XtraReport1";
customers = new List<object>();
foreach (Customer customer in new DataWorkspace().NorthWind_XtraReportsData.Customers) {
customers.Add(customer.Country);
}
}
}
}
The report is now ready. Run the application, choose a country and get the result.