本帖最后由 sammer110 于 2023-6-17 16:34 编辑
版本:AR 16.2.1
报表数据源使用dataset数据集,需要通过代码直接赋值进行打印,无需弹出预览;
经测试不进入PageDocument_LocateDataSource事件
报表文件:
winform代码如下:
private void button3_Click(object sender, EventArgs e)
{
string path = Application.StartupPath + $"\\Reports\\test.rdlx";
GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(path));
GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
pageDocument.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(PageDocument_LocateDataSource);
//打印
pageDocument.Print(false, true, false);
}
private void PageDocument_LocateDataSource(object sender, LocateDataSourceEventArgs args)
{
if (args.DataSet.Query.DataSourceName == "DataSource1")
{
if (args.DataSet.Name == "DataSet1")
{
args.Data = GetData();
}
}
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Col1");
dt.Columns.Add("Col2");
dt.Columns.Add("Col3");
dt.Rows.Add(1, 1, 1);
dt.Rows.Add(2, 1, 1);
dt.Rows.Add(3, 1, 1);
dt.Rows.Add(4, 1, 1);
dt.Rows.Add(5, 1, 1);
dt.Rows.Add(6, 1, 1);
return dt;
}
报错如下:
|