翻譯|使用教程|編輯:董玉霞|2022-06-29 11:40:52.513|閱讀 435 次
概述:FastReport.NET 報表可以具有在生成報表之前顯示的對話框表單。它們允許您設置一些文本、布爾值或數字變量。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
FastReport.NET 報表可以具有在生成報表之前顯示的對話框表單。它們允許您設置一些文本、布爾值或數字變量。這些可以是文本字段、表格、列表、下拉列表、日期、復選框,甚至是帶有復選框的列表。
通常,對話框表單用于過濾報表中的數據或選擇報表行為的標準。但是今天我們將討論對話形式的另一種可能用途。
讓我們看一下需要在顯示之前為報表輸入數據的情況。當涉及到單個文本字段、復選框、列表時,這是一個簡單的案例。
但是,如果您有一個數據表,并且想要在構建報告之前手動調整它怎么辦?
這是 Grid 網格 組件可以提供幫助的地方。這是一個包含數據的表格,我們可以在構建報告之前在對話框中顯示這些數據。
讓我們在報表中添加一個對話框窗體并在其上放置一個 Grid 控件。讓我們通過右鍵單擊來調用它的上下文菜單:
選擇“編輯列...”以將列添加到表中。
在列編輯窗口中添加三列 - 姓名、地址、電話。查看Customers.Name 屬性。在這里,我們引用了尚未在報告中的客戶數據源。但我們稍后會使用腳本添加它。對于其余列,您需要設置適當的屬性。
報告頁面模板非常簡單——只有一個三列的 Table 對象。我們將把它填充到報告腳本中。
現在,讓我們為報表添加 StartReport 事件處理程序:
報告腳本:
public class ReportScript
{
//Data structure for table
public class Customer
{
public string Name {get; set; }
public string Address {get; set; }
public string Phone {get; set; }
public Customer(string name, string address, string phone)
{
Name = name;
Address = address;
Phone = phone;
}
}
private void _StartReport(object sender, EventArgs e)
{
//List of customers
Listcustomers = new List();
//Fill the list of customers with default data
customers.Add(new Customer("Kevin Smith", "221 52nd st, Brooklyn, NY, United States", "+12127599755"));
customers.Add(new Customer("Justin Ford", "1556 Broadway, suite 416, NY, United States", "+12145678900"));
customers.Add(new Customer("Amanda Stephenson", "455 Larkspur Dr., CA, United States", "+14105175379"));
// Register the data source in a report
Report.RegisterData(customers, "Customers");
//Set the data source in the table
Grid1.DataSource = Report.GetDataSource("Customers");
//Set fields in cells
Cell6.Text = "[Customers.Name]";
Cell7.Text = "[Customers.Address]";
Cell8.Text = "[Customers.Phone]";
}
}
在這種情況下,我們設置了將用于在對話框和報表中顯示表中的行的 Customer 數據結構。接下來,我們創建一個客戶數據源并使用客戶實例填充它。然后我們在報表中注冊接收到的數據源。你還記得我們是如何為 Grid 對象中的列設置數據字段的嗎?我們提到了這個數據源。在這里,我們將源中的字段分配給頁面模板中的表格單元格(表格對象)。
現在讓我們為報表頁面上的 Table 對象創建一個 ManualBuild 事件處理程序。在頁面上構建對象后調用此事件,并允許您更改準備顯示的表格。因此,我們可以使用腳本更改表格中的文本。
private void Table1_ManualBuild(object sender, EventArgs e)
{
//Set the data source
DataSourceBase rowData = Report.GetDataSource("Customers");
//Initialize the data
rowData.Init();
//Display the first row of data
Table1.PrintRow(0);
//Display the column
Table1.PrintColumns();
//Loop through all rows of data in source
while (rowData.HasMoreRows)
{
//Output the next line of data
Table1.PrintRow(1);
//Output the column
Table1.PrintColumns();
//take the following entry from the source
rowData.Next();
}
}
在這里,我們通過簡單地遍歷所有數據行來填充表格。
讓我們運行報告。我們將看到的第一件事是一個帶有表格的對話框:
讓我們雙擊第一個單元格來編輯它的文本:
在報表控件 FastReport.NET 單擊確定并檢查結果:
如您所見,我們的默認數據已更改為我們手動輸入的數據。通過這種方式,您可以讓用戶在構建報表之前手動更改數據。此示例顯示如何使用來自腳本的數據填充表,但沒有什么能阻止您使用來自源的數據填充它。
更多產品授權信息點擊查看FastReport.NET價格,或者咨詢慧都在線客服。
FastReport.NET技術QQ群:702295239 歡迎進群一起討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn