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 Col1 value, Col2 value, and Col3 value text boxes then clicking the button.
button. Once data displays in the grid, you can add more rows to the grid by entering values in theThe following steps describe how to get the .NET data grid to handle customized column definitions when using a database query:
- 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.
- 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).
- Return to the DataGrid. To display the property editor, under the Data category, click the TableStyles property.
- Add a table style.
- In the new table style, in the MappingName column, enter
Table1
. - To display the property editor, click the GridColumnStyles property.
- In the GridColumnStyles property editor, add members for the various data columns.
- 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.
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 |
Previous topic Robotic Automation sample solutions and examples Next topic Sample Robotic Automation solution: Cancel event