报表开发工具FastReport .NET——如何将初步数据输入表格的交互式报告

本篇文章将为大家带来如何将初步数据输入表格的交互式报告。

如您所知,

通常,对话框表单用于过滤报表中的数据或选择报表行为的标准。但是今天我们将讨论对话形式的另一种可能用途。

让我们看一下需要在显示之前为报表输入数据的情况。当涉及到单个文本字段、复选框、列表时,这是一个简单的案例。但是,如果您有一个数据表,并且想要在构建报告之前手动调整它怎么办/p>

这是 Grid 网格 组件可以提供帮助的地方。这是一个包含数据的表格,我们可以在构建报告之前在对话框中显示这些数据。

让我们在报表中添加一个对话框窗体并在其上放置一个 Grid 控件。让我们通过右键单击来调用它的上下文菜单:

报表开发工具FastReport .NET——如何将初步数据输入表格的交互式报告

选择“编辑列…”以将列添加到表中。

报表开发工具FastReport .NET——如何将初步数据输入表格的交互式报告

在列编辑窗口中添加三列 – 姓名、地址、电话。查看Customers.Name 属性。在这里,我们引用了尚未在报告中的客户数据源。但我们稍后会使用脚本添加它。对于其余列,您需要设置适当的属性。

报告页面模板非常简单——只有一个三列的 Table 对象。我们将把它填充到报告脚本中。

报表开发工具FastReport .NET——如何将初步数据输入表格的交互式报告

现在,让我们为报表添加 StartReport 事件处理程序:

报表开发工具FastReport .NET——如何将初步数据输入表格的交互式报告

报告脚本:

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 事件处理程序。在页面上构建对象后调用此事件,并允许您更改准备显示的表格。因此,我们可以使用脚本更改表格中的文本。

报表开发工具FastReport .NET——如何将初步数据输入表格的交互式报告

 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 技术交流群:702295239    欢迎一起进群讨论

更多FastReport线上公开课、中文教程资讯请上中文网获取

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年3月12日
下一篇 2022年3月12日

相关推荐

发表回复

登录后才能评论