經過驗證是對的。
table第一行添加標題,也就是拖過來的文本label,第二行開始綁定數據源的字段。
先設計報表的靜態部分,再用代碼注冊數據源,然后設計,添加注冊的數據源,綁定字段。
1 2 var report = new Report(); 3 report.Load(ProTaskReport); 4 report.RegisterData(new [] {header}, "header"); 5 report.RegisterData(body, "body"); 6 report.RegisterData(sum, "sum"); 7 //report.Design(); 8 report.Print();
在報表內添加table的print行。
1 private void Table2_ManualBuild(object sender, EventArgs e) 2 { 3 DataSourceBase body = Report.GetDataSource("sum"); 4 body.Init(); 5 Table2.PrintRow(0); 6 Table2.PrintColumns(); 7 while(body.HasMoreRows){ 8 Table2.PrintRow(1); 9 Table2.PrintColumns(); 10 body.Next(); 11 } 12 }
2017-5-17 補充
其實這樣做沒必要,可以將數據部分寫在data body里面,綁定數據源字段即可。