Accessing the Report Preview Model in LightSwitch

DevExpress Data Blog
20 July 2011

In this blog post I will explain another small feature of XtraReports for LightSwitch: the ability to access the ReportPreviewModel from code. For example, I will show how you can provide custom editors for report parameters in a LightSwitch application.

Starting with our next minor release, in addition to the capability of passing parameters from LightSwitch queries to reports, …

LightSwitch queries and XtraReports parameters

 … we have also added a new CustomizeReportPreviewModel method, which can be specifically used for accessing the ReportPreviewModel

  Accessing Report Preview Model in LightSwitch

The above code is generated automatically in a ReportPreviewScreen's code behind. You should not rename this method or modify its type and visibility scope (public void).

Now, let’s use a ComboBoxEdit (which is part of our DevExpress Editors for Silverlight) as a custom parameter editor.

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> categories;

        void model_CustomizeParameterEditors(object sender, CustomizeParameterEditorsEventArgs e) {
            if (e.Parameter.Name == "CategoryName") {
                var editor = new ComboBoxEdit();
                editor.ItemsSource = categories;
                editor.IsTextEditable = false;
                e.Editor = editor;
                e.BoundDataMember = "EditValue";
            }
        }

        partial void ReportPreviewScreen_Activated() {
            this.ReportTypeName = "XtraReport1";
            categories = new List<object>();
            foreach (Category category in new DataWorkspace().NorthWindData.Categories) {
                categories.Add(category.CategoryName);
            }
        }
    }
}

Here is the result!

 Creating custom parameter editors with XtraReports for LightSwitch

 Please feel free to leave your comments below. 

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.