Report to print MVVM

7 posts, 2 answers
  1. Cynthia
    Cynthia avatar
    10 posts
    Member since:
    Apr 2017

    Posted 26 Nov 2019 Link to this post

    Hi, I need suport to pass my telerik report to MVVM pattern

    right now my report is send to the printer, and all the programming is in xaml and their code behind:

    in the user control xaml:

                <tr:ReportViewer Name="ReportViewer1" Width="0" Height="0" Grid.Column="0" Grid.Row="2">
                    <tr:ReportViewer.ReportSource>
                        <telerikReporting:TypeReportSource TypeName="ReportLibrary, ReportLibrary" />
                    </tr:ReportViewer.ReportSource>
                </tr:ReportViewer>

     

    and in the user control code behind:

            public ucInventarioPTaVentas()
            {
                InitializeComponent();

                _InventarioVendido = new ObservableCollection<InventarioPTaVentasCL>();

                var TRS = new TypeReportSource();

                TRS.TypeName = typeof(rpMaterialVendido).AssemblyQualifiedName;
                ReportViewer1.ReportSource = TRS;

            }

            private void btnImprimir_Click(object sender, RoutedEventArgs e)
            {
                foreach (var item in grdColeccion.Items)
                {
                    if (((InventarioPTaVentasCL)item).seleccionada)
                    {
                        _InventarioVendido.Add((InventarioPTaVentasCL)item);
                    }
                }
                
                #region ImprimeReporteDeVentas
                Report rpt;
                rpt = new rpMaterialVendido();

                rpt.DataSource = _InventarioVendido;

                Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
                instanceReportSource.ReportDocument = rpt;
                instanceReportSource.Parameters.Add("pCliente", cbClienteNombre.Text);
                ReportViewer1.ReportSource = instanceReportSource;

                ReportViewer1.PrintReport();

                #endregion
            }

     

    But, for all my app, I using the MVVM pattern, obviously on my ViewModel I have the observablecollection and the parametrs needed to my report, and I don't know how make the report with the MVVM pattern, can you help me??

     

     

     

  2. Neli
    Admin
    Neli avatar
    273 posts

    Posted 29 Nov 2019 Link to this post

    Hello Cynthia,

    You may use the approach described in Using the WPF Report Viewer in an MVVM scenario KB article. 

    The attached project demonstrates the solution.

    Regards,
    Neli
    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. Cynthia
    Cynthia avatar
    10 posts
    Member since:
    Apr 2017

    Posted 29 Nov 2019 in reply to Neli Link to this post

    well, i reviewed this solution before, but, on it I don't find how i can sent the report to the printer directly, without show it at the screen, as my report case, and how I can sent the DataSource and the parameters, and I can't runner it never, the project can't charge the references, I try to charger it manually, but, don't work...
  4. Answer
    Neli
    Admin
    Neli avatar
    273 posts

    Posted 04 Dec 2019 Link to this post

    Hi Cynthia,

    If you would like to print the report directly, without showing it in the viewer, you can use the ReportProcessor.PrintReport Method. You may choose between:

    PrintReport(ReportSource, PrinterSettings);

    PrintReport(ReportSource, PrinterSettings, String).

    Regards,
    Neli
    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
  5. Cynthia
    Cynthia avatar
    10 posts
    Member since:
    Apr 2017

    Posted 04 Dec 2019 in reply to Neli Link to this post

    ok, thanks a lot, an other more question, if I want to show the printer selecter on the screen, how I can do this?
  6. Answer
    Neli
    Admin
    Neli avatar
    273 posts

    Posted 09 Dec 2019 Link to this post

    Hi Cynthia,

    Basically, if you don't specify the PrinterSettings or they are invalid, the Print dialog will be automatically displayed. For example:

    reportProcessor.PrintReport(uriReportSource, null);

    Regards,
    Neli
    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
  7. Cynthia
    Cynthia avatar
    10 posts
    Member since:
    Apr 2017

    Posted 10 Dec 2019 in reply to Neli Link to this post

    oooohhh, ok, thank you very much... I'm stay learning...
Back to Top