我有一个winform,利用backgroundworker收集文件并按日期,文件类型等过滤它们。这些文件保存在名为“allfiles”的列表中。我想在reportviewer中显示此列表。根据我到目前为止所发现的,最好的方法是将列表解析为数据表,然后将该数据表设置为“report.rdlc”文件的数据源,然后再将该文件加载到reportviewer中。
这是我用来将列表解析为数据表的代码:
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();
}
这是我尝试使用的代码,我的报告查看器上显示了这些数据:
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);
我遇到的问题是,当我运行此代码时,报表查看器仍为空,即没有信息的空白白板(请参阅screecap of reportviewer)。这似乎应该是一个简单的解决方案,但我尝试过的任何工作都没有。