本篇文章将为大家带来如何将初步数据输入表格的交互式 告。
如您所知,
通常,对话框表单用于过滤 表中的数据或选择 表行为的标准。但是今天我们将讨论对话形式的另一种可能用途。
让我们看一下需要在显示之前为 表输入数据的情况。当涉及到单个文本字段、复选框、列表时,这是一个简单的案例。但是,如果您有一个数据表,并且想要在构建 告之前手动调整它怎么办/p>
这是 Grid 格 组件可以提供帮助的地方。这是一个包含数据的表格,我们可以在构建 告之前在对话框中显示这些数据。
让我们在 表中添加一个对话框窗体并在其上放置一个 Grid 控件。让我们通过右键单击来调用它的上下文菜单:


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