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:
I hope I've been clear. Thanks for the answer in advance!
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();
}