How to set all tables and relations from DataSet enabled in report?
Question: How to set all tables and relations from DataSet enabled in report?
Answer:
Use this snippet to set all tables from your data source as enable:
1 2 3 4 |
foreach (FastReport.Data.DataSourceBase tbl in report.Dictionary.DataSources) { tbl.Enabled = true; } |
Then add relations:
1 2 3 4 |
for (int i = 0; i < ds.Relations.Count; i++) { report.RegisterData(ds.Relations[i], "relation" + i); } |
And set relations enabled:
1 2 3 4 |
foreach (FastReport.Data.Relation rl in report.Dictionary.Relations) { rl.Enabled = true; } |
And full code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Report report = new Report(); DataSet ds = new DataSet(); ds.ReadXml("EstimateFile.xml"); report.RegisterData(ds, "ds"); foreach (FastReport.Data.DataSourceBase tbl in report.Dictionary.DataSources) { tbl.Enabled = true; } for (int i = 0; i < ds.Relations.Count; i++) { report.RegisterData(ds.Relations[i], "relation" + i); }
foreach (FastReport.Data.Relation rl in report.Dictionary.Relations) { rl.Enabled = true; } |