Accessing the Report Preview Model in LightSwitch

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. 

6 comment(s)
Renante Malubag

Hi,

Please elaborate more on how we are going to accomplished a combobox in our report. I can't understand the blog.

I will be glad if you do so.

6 September, 2011
Renante Malubag

Hi,

Please elaborate more on how we are going to accomplished a combobox in our report. I can't understand the blog.

I will be glad if you do so.

6 September, 2011
George (DevExpress)

Hi. Would you clarify what is unclear in particular? Please note that you can always address your questions to our Support Team (devexpress.com/sc) to receive an answer within 24 hours.

6 September, 2011
Renante Malubag

Hi, I am confuse on the auto generated code behind the screen with that of ther code given.  Am I going to replace the code that was previously generated with the new one?

6 September, 2011
Renante Malubag

Hi, I am confused on the auto generated code behind the screen with that of ther code given.  Am I going to replace the code that was previously generated with the new one?

6 September, 2011
George (DevExpress)

Yes, after writing the given code your application should work as expected. If this is not the case, please feel free to send your project to our Support Team at devexpress.com/sc.

9 September, 2011

Please login or register to post comments.