翻譯|使用教程|編輯:董玉霞|2022-06-29 11:40:52.513|閱讀 422 次
概述:FastReport.NET 報表可以具有在生成報表之前顯示的對話框表單。它們允許您設(shè)置一些文本、布爾值或數(shù)字變量。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
FastReport.NET 報表可以具有在生成報表之前顯示的對話框表單。它們允許您設(shè)置一些文本、布爾值或數(shù)字變量。這些可以是文本字段、表格、列表、下拉列表、日期、復(fù)選框,甚至是帶有復(fù)選框的列表。
通常,對話框表單用于過濾報表中的數(shù)據(jù)或選擇報表行為的標(biāo)準(zhǔn)。但是今天我們將討論對話形式的另一種可能用途。
讓我們看一下需要在顯示之前為報表輸入數(shù)據(jù)的情況。當(dāng)涉及到單個文本字段、復(fù)選框、列表時,這是一個簡單的案例。
但是,如果您有一個數(shù)據(jù)表,并且想要在構(gòu)建報告之前手動調(diào)整它怎么辦?
這是 Grid 網(wǎng)格 組件可以提供幫助的地方。這是一個包含數(shù)據(jù)的表格,我們可以在構(gòu)建報告之前在對話框中顯示這些數(shù)據(jù)。
讓我們在報表中添加一個對話框窗體并在其上放置一個 Grid 控件。讓我們通過右鍵單擊來調(diào)用它的上下文菜單:
選擇“編輯列...”以將列添加到表中。
在列編輯窗口中添加三列 - 姓名、地址、電話。查看Customers.Name 屬性。在這里,我們引用了尚未在報告中的客戶數(shù)據(jù)源。但我們稍后會使用腳本添加它。對于其余列,您需要設(shè)置適當(dāng)?shù)膶傩浴?
報告頁面模板非常簡單——只有一個三列的 Table 對象。我們將把它填充到報告腳本中。
現(xiàn)在,讓我們?yōu)閳蟊硖砑?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]"; } }
在這種情況下,我們設(shè)置了將用于在對話框和報表中顯示表中的行的 Customer 數(shù)據(jù)結(jié)構(gòu)。接下來,我們創(chuàng)建一個客戶數(shù)據(jù)源并使用客戶實例填充它。然后我們在報表中注冊接收到的數(shù)據(jù)源。你還記得我們是如何為 Grid 對象中的列設(shè)置數(shù)據(jù)字段的嗎?我們提到了這個數(shù)據(jù)源。在這里,我們將源中的字段分配給頁面模板中的表格單元格(表格對象)。
現(xiàn)在讓我們?yōu)閳蟊眄撁嫔系?Table 對象創(chuàng)建一個 ManualBuild 事件處理程序。在頁面上構(gòu)建對象后調(diào)用此事件,并允許您更改準(zhǔn)備顯示的表格。因此,我們可以使用腳本更改表格中的文本。
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(); } }
在這里,我們通過簡單地遍歷所有數(shù)據(jù)行來填充表格。
讓我們運行報告。我們將看到的第一件事是一個帶有表格的對話框:
讓我們雙擊第一個單元格來編輯它的文本:
在報表控件 FastReport.NET 單擊確定并檢查結(jié)果:
如您所見,我們的默認(rèn)數(shù)據(jù)已更改為我們手動輸入的數(shù)據(jù)。通過這種方式,您可以讓用戶在構(gòu)建報表之前手動更改數(shù)據(jù)。此示例顯示如何使用來自腳本的數(shù)據(jù)填充表,但沒有什么能阻止您使用來自源的數(shù)據(jù)填充它。
更多產(chǎn)品授權(quán)信息點擊查看FastReport.NET價格,或者咨詢慧都在線客服。
FastReport.NET技術(shù)QQ群:702295239 歡迎進群一起討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn