This is a migrated thread and some comments may be shown as answers.

Report parameter in MVVM

3 Answers 183 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SteSa
Top achievements
Rank 1
SteSa asked on 01 Oct 2018, 02:05 PM

Hi,

i'm try to pass two parameter to my report, in WPF/MVVM scenario, but the report can't see(Missing or invalid parameter value.). To be sure that report have the right parameters, i've put a texbox(into report) and set his value to the parameter's value. When i refresh report, "Missing or invalid parameter value" disappare, the textbox value have the correct ID but report no fetch record from Datasource.

This is my code:

XAML:

                <tr:ReportViewer telerik:StyleManager.Theme="Material" IsEnabled="{Binding ReportEnabled}"
                                 ReportSource="{Binding FormInternalReport_Source, Mode=TwoWay}" 
                                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="2" />

 

ViewModel:

       private ReportSource _FormInternalReport_Source;
        public ReportSource FormInternalReport_Source
        {
            get { return _FormInternalReport_Source; }
            set
            {
                Set<ReportSource>(() => this.FormInternalReport_Source, ref _FormInternalReport_Source, value);
            }
        }

        private void ExecuteInsert(object parameter)
        {

            //Report are enable only when Insert Button is clicked
            ReportEnabled = true;

            FormInternalReport_Source = new InstanceReportSource { ReportDocument = new Form_Internal(Report_ID) };
            FormInternalReport_Source.Parameters.Add(new Telerik.Reporting.Parameter(new Telerik.Reporting.Parameter("ID", Report_ID) ));                        
            FormInternalReport_Source.Parameters.Add(new Telerik.Reporting.Parameter(new Telerik.Reporting.Parameter("LanguageID", 1) ));


            try
            {
                RaisePropertyChanged("FormInternalReport_Source");
            }
            catch(Exception ex)
            { }


        }
Can someone help me?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Ivan Hristov
Telerik team
answered on 04 Oct 2018, 07:34 AM
Hi Stefano,

Examining the attached code, it seems that the assignment of the report source should be done after setting its parameters, because the line:
FormInternalReport_Source = new InstanceReportSource { ReportDocument = new Form_Internal(Report_ID) };
will trigger the report refresh without parameters, since they are set at the following 2 lines.
I suggest to refactor the ExecuteInsert code like this:

FormInternalReport_Source.Parameters.Add("ID", Report_ID);
FormInternalReport_Source.Parameters.Add("LanguageID", 1);
FormInternalReport_Source = new InstanceReportSource { ReportDocument = new Form_Internal(Report_ID) };

Let us know if this helps.

Regards,
Ivan Hristov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
SteSa
Top achievements
Rank 1
answered on 04 Oct 2018, 07:45 AM

Hi Ivan,

if i assign the report parameter before new istance i have an exception of null reference because FormInternalReport_Source is null. I try also this:

FormInternalReport_Source = new InstanceReportSource { ReportDocument = new Form_Internal(Report_ID) };

FormInternalReport_Source.Parameters.Add("ID", Report_ID);
FormInternalReport_Source.Parameters.Add("LanguageID", 1);
FormInternalReport_Source = new InstanceReportSource { ReportDocument = new Form_Internal(Report_ID) };
but nothing.

 

Stefano

0
SteSa
Top achievements
Rank 1
answered on 04 Oct 2018, 03:46 PM

Hi,

finally i find the solution;

var instanceReportSource = new Telerik.Reporting.InstanceReportSource();                
instanceReportSource.ReportDocument = new Form_Internal();
instanceReportSource.Parameters.Add(new Telerik.Reporting.Parameter("ID", message));
instanceReportSource.Parameters.Add(new Telerik.Reporting.Parameter("LanguageID", 1));
FormInternalReport_Source = instanceReportSource;

 

https://docs.telerik.com/reporting/t-telerik-reporting-instancereportsource

Thanks

Stefano

Tags
General Discussions
Asked by
SteSa
Top achievements
Rank 1
Answers by
Ivan Hristov
Telerik team
SteSa
Top achievements
Rank 1
Share this question
or