Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've added a ReportViewer in a WPF app via the XAML designer of my main window and I'd like to add an existing rdlc file to it.

I'd like my reportviewer to show an empty rdlc file (without the parameters) on startup, and later upon selecting a row from my datagrid (bound to an observablecollection) change its parameters accordingly and show the filled report definition instead of the empty one.

I'll make a button with the selected row as commandparameter and the relevant events and everything, I just need to be able to pass data to the report. I realize it is not an easy question so I'll try to simplify:

  1. How to add an existing rdlc file to a ReportViewer (MVVM, WPF) ?
  2. I push a button -> relevant command gets the item from my observablecollection as parameter (a row in my datagrid) -> How to pass the data parts of this item to the unfilled (or overwrite if filled of course) parts of the report?

I hope I've been clear. Thanks for the answer in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
413 views
Welcome To Ask or Share your Answers For Others

1 Answer

After you set up your initilizeMethod with correct path to the report and dataset name something like this.

private void initializeReport()
        {
            this.mform_components = new System.ComponentModel.Container();
            Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();

            this.ProductBindingSource = new System.Windows.Forms.BindingSource(this.mform_components);
            ((System.ComponentModel.ISupportInitialize)(this.ProductBindingSource)).BeginInit();

            reportDataSource1.Name = "DataSet4";
            reportDataSource1.Value = this.ProductBindingSource;

            this.viewerInstance.LocalReport.DataSources.Add(reportDataSource1);
            this.viewerInstance.LocalReport.ReportEmbeddedResource = "YourReport.rdlc";
            this.viewerInstance.ZoomPercent = 95;
            this.windowsFormsHost1.Width = 680;

            ((System.ComponentModel.ISupportInitialize)(this.ProductBindingSource)).EndInit();
    }

Only thing that should be left is specifing the object you want to se in your report.

private System.Windows.Forms.BindingSource ProductBindingSource;
        private void startReport()
        {
            YourClass item  = (YourClass)DataGridView.SelectedItem;
            this.ProductBindingSource.DataSource = item;

            this.viewerInstance.RefreshReport();
            this.viewerInstance.Refresh();
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...