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