Blogs

DevExpress Reporting Blog

Accessing the Report Preview Model in LightSwitch

     

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. 

Published Jul 20 2011, 08:06 AM by George (DevExpress)
Bookmark and Share

Comments

 

Renante Malubag said:

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.

September 6, 2011 8:48 AM
 

Renante Malubag said:

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.

September 6, 2011 8:48 AM
 

George (DevExpress) said:

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.

September 6, 2011 9:06 AM
 

Renante Malubag said:

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?

September 6, 2011 9:16 AM
 

Renante Malubag said:

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?

September 6, 2011 9:16 AM
 

George (DevExpress) said:

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.

September 9, 2011 6:19 AM

About George (DevExpress)

Joined Developer Express on April 4, 2008
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.