Report parameter in MVVM

4 posts, 0 answers
  1. SteSa
    SteSa avatar
    4 posts
    Member since:
    Aug 2018

    Posted 01 Oct 2018 Link to this post

    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.

  2. Ivan Hristov
    Admin
    Ivan Hristov avatar
    184 posts

    Posted 04 Oct 2018 Link to this post

    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
  3. SteSa
    SteSa avatar
    4 posts
    Member since:
    Aug 2018

    Posted 04 Oct 2018 in reply to Ivan Hristov Link to this post

    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

  4. SteSa
    SteSa avatar
    4 posts
    Member since:
    Aug 2018

    Posted 04 Oct 2018 in reply to SteSa Link to this post

    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

Back to Top