FastReport.NET 表可以具有在生成 表之前显示的对话框表单。它们允许您设置一些文本、布尔值或数字变量。


告页面模板非常简单——只有一个三列的 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 customersListcustomers = 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 | 在线试用
FastReport.NET技术
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!