I have a winform that utilizes a backgroundworker to gather files and filter them by date, filetype, etc. These files are kept in a list called "allfiles". I would like to display this list in a reportviewer. From what I have found so far, the best way to do this is to parse the list to a datatable, then set that datatable as the datasource for a "report.rdlc" file before loading that file into the reportviewer.
This is the code I use to parse the list into a datatable:
DataTable dtable = new DataTable();
dtable.Columns.Add("Field Name", typeof(string));
foreach (string x in allfiles.ToArray())
{
DataRow dataRow = dtable.NewRow();
dataRow["Field Name"] = x;
dtable.Rows.Add(dataRow);
dtable.AcceptChanges();
}
This is the code I use to try and have that data appear on my reportviewer:
BindingSource thisIsABindingSource = new BindingSource();
thisIsABindingSource.DataSource = dtable;
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
var reportDataSource1 = new ReportDataSource { Name = "list", Value = thisIsABindingSource};
string exeFolder = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
reportViewer1.LocalReport.ReportPath = exeFolder + @"\Report1.rdlc";
reportViewer1.LocalReport.ReportEmbeddedResource = exeFolder + @"\Report1.rdlc";
reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
The problem I am having is that when I run this code the report viewer remains empty i.e. a blank white sheet with no information (see screecap of reportviewer). This seems like it should be an easy fix but nothing I have tried has worked.