Table of Contents

Sample Robotic Automation solution: .NET DataGrid

This sample solution shows how to use custom column names in a .NET DataGrid in place of the metadata associated with the data source by using Pega Robotic Automation.

Usually, the column headings that are displayed in a data grid show the text that is associated with the data source. To change these names, you must assign a style for the table and then map the custom column headings to the columns of the data source.

Project items

  • Automation: getTableData
  • Windows Form1
    • The data source for the data grid is a script in the automation. NewStyle is added for DataGrid – see the steps in Special considerations.

Automation details

The automation getTableData contains two script methods. One method creates a data source with columns Col1, Col2, and Col3 and sample data. The second method lets the user enter additional data to the table. These methods take the place of queries to a database or connections to a data source, which would be used in practice.

Scripts

  Name: MakeTable

  Parameters: none

  Result type: DataTable

  DataSet ds = new DataSet();

  DataTable table = ds.Tables.Add("MyTable");

  table.Columns.Add("Col1");

  table.Columns.Add("Col2");

  table.Columns.Add("Col3");

  DataRow row = table.NewRow();

  row["Col1"] = "abc";

  row["Col2"] = "def";

  table.Rows.Add(row);

  DataRow row2 = table.NewRow();

  row2["Col1"] = "ghi";

  row2["Col2"] = "jkl";

  table.Rows.Add(row2);

  return table;
       
  Name: AddTableRow

  Parameters: DataTable table, string col1, string col2, string col3

  Result type: void

  DataSet ds = new DataSet();

  DataTable table = ds.Tables.Add("MyTable");

  table.Columns.Add("Col1");

  table.Columns.Add("Col2");

  table.Columns.Add("Col3");

  DataRow row = table.NewRow();

  row["Col1"] = "abc";

  row["Col2"] = "def";

  table.Rows.Add(row);

  DataRow row2 = table.NewRow();

  row2["Col1"] = "ghi";

  row2["Col2"] = "jkl";

  table.Rows.Add(row2);

  return table;
       

Special considerations

The sample solution uses a script to populate the data grid. The data columns are Col1, Col2, and Col3. The grid has been modified to have the following columns: MS, Col-2, and Last Col.

To use the solution, click the Do Query button. Once data displays in the grid, you can add more rows to the grid by entering values in the Col1 value, Col2 value, and Col3 value text boxes then clicking the Add Row button.

The following steps describe how to get the .NET data grid to handle customized column definitions when using a database query:

  1. Create a form with a DataGrid and TableView, then bind the DataGrid to the TableView by using the TableView as the grid’s DataSource property value.
  2. Create the query by using any query provider and bind this to the TableView by setting the query to the tableview’s TableProvider property value. This updates the grid display in the form, displaying the various columns from the query with default properties (width, caption, and so on).
  3. Return to the DataGrid. To display the property editor, under the Data category, click the TableStyles property.
  4. Add a table style.
  5. In the new table style, in the MappingName column, enter Table1.
  6. To display the property editor, click the GridColumnStyles property.
    The DataGridTableStyle Collection Editor
  7. In the GridColumnStyles property editor, add members for the various data columns.
  8. For each column, specify the MappingName to tie the column to a particular column in the grid – select the grid column from a list. You can also use this editor to specify the width, alignment, and header text on each column.
The key to making this work is the entry of the Table1 mapping name on the table style. This is used to equate a table with a visual style. Internally, Studio always sets this text from the TableView object to be Table1.

You can download completed solutions for each version in the following table:

Studio version Built by using this build Sample solution download
8.0 8.0.1037 DBGridTest 8.0
8.0 SP1 8.0.2037 DBGridTest 8.0 SP1
19.1 19.1.2.0 DBGridTest 19.1
Suggest Edit

50% found this useful

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.