Wednesday 1 May 2013

How to bind DevExpress Reporting Parameter?

Introduction: This article represents that how can you make a DevExpress reporting Parameter as a dropdown or how can you bind a parameter with a list of values in your LightSwitch Applicaiton? So that you don't want to write any thing in the parameter. Because at the time of writing user can make the mistake.

Gettting help from DevExpress.com
Step to Reproduce

Step1: Go to the Server section in you lightswitch Application and create new report using the DevExpress Reporting tool.

Step2: Create the Parameters on the reports which you want.

Step3: Create a new Screen using the Report Preview Screen. and then click on the write code on that display.


Step4: Call you report by writing the full path of your report like as below.


partial void ReportDaily_Activated()
        {
            // Assign the name of the report, which you want to preview in this screen.
            this.ReportTypeName = "LightSwitchApplication.Reports.DailyReport";
        }

Step5: Run your application and check your report. You will see all the parameters on the report and SalesPerson Parameter is as a textfield.


How can you bind 'SalesPerson' parameter with some values?

Step6: Import two namespaces with your class of DevExpress.


using DevExpress.Xpf.Editors;

using DevExpress.Xpf.Printing;
 
Step7: write the following code to bind your paramter.



public void CustomizeReportPreviewModel(DevExpress.Xpf.Printing.ReportPreviewModel model)

        {
            model.CustomizeParameterEditors += model_CustomizeParameterEditors;
        }
        List<object> SalePersonMasters;

        void model_CustomizeParameterEditors(object sender, CustomizeParameterEditorsEventArgs e)
        {
            if (e.Parameter.Name == "SalesPerson")          //"SalesPerson" is the parameter name which used on Reporting
            {
                var editor = new ComboBoxEdit();
                editor.ItemsSource = SalePersonMasters;
                editor.IsTextEditable = false;
                e.Editor = editor;
                e.BoundDataMember = "EditValue";
            }
        }
        partial void ReportDaily_Activated()
        {
            // Assign the name of the report, which you want to preview in this screen.
            this.ReportTypeName = "LightSwitchApplication.Reports.DailyReport";
            SalePersonMasters = new List<object>();
            var SPName = (from spname in this.DataWorkspace.BooksCrmData.SalePersonMasters
                          select spname).OrderBy(O => O.SalePersonID);
            foreach (SalePersonMaster sale in SPName)
            {
                SalePersonMasters.Add(sale.SPName);
            }
        }
 

Step8: Run your LS application by hitting F5 button and you see your parameter 'SalesPerson' in new look.


Step9: Now the question is that how can you add a default value in the drop-down parameter on the report? Go back to report designer display
 and go to the parameter section add default value for your paramter.

 Step10: Run your application and check that default value has been added on your report.


I hope that the above article will help you to bind the parameter on the reports.

Thanks!

No comments: