文檔金喜正規買球>>FastReport中文文檔>>示例 6.使用數據源
示例 6.使用數據源
在所有示例中,我們都打印了一個包含普通文本的表格。在本示例中,我們將演示如何使用數據源創建表格。為此,我們將創建一個格式如下的表格:

我們將創建 ManualBuild 事件處理程序,它將執行以下操作:
- 獲取報告中定義的數據源。
- 初始化(填充數據)。
- 打印表格行數,打印次數與數據源中的行數相同。
以下是處理程序的代碼:
private void Table1_ManualBuild(object sender, EventArgs e) { // get the data source by its name DataSourceBase rowData = Report.GetDataSource("Products"); // initialize it rowData.Init(); // printing the table header Table1.PrintRow(0); Table1.PrintColumns(); // loop through the data source rows while (rowData.HasMoreRows) { // printing the table row Table1.PrintRow(1); Table1.PrintColumns(); // select the next data row rowData.Next(); } // printing the table footer Table1.PrintRow(2); Table1.PrintColumns(); }
如果我們運行該報告,會得到以下結果:
