- Overview
- Method 1: Cloning columns
- Method 2: Creating the columns
- Using the new column
How to clone and use columns in a Table control?
In some cases, a Table control must be filled with an unknown number of columns (when creating the control). Two methods can be used to dynamically build columns in a Table control: Method 1: Cloning columns ControlClone is used to clone (duplicate) an existing control in order to create a copy. This function can also be used on a column found in a Table control. The new column is automatically added at the end of existing columns. To create a new column: - Create a Table control.
- In the Table control, define the column that will be used as "template for cloning".
- Clear the content of Table control (TableDeleteAll).
- Delete the previous cloned columns (ControlDelete).
- Create the new columns (ControlClone).
- Fill the Table control with data.
Code example:
NbFixedColumns is int NbNewColumns is int NewColumnName is string // Clear the table TableDeleteAll(TABLE_YearlyStat) // Delete the previous cloned columns NbFixedColumns = 3 // for example, 2 fixed columns + the column to clone FOR nIndex = TableCount(TABLE_YearlyStat,toColumn) TO NbFixedColumns STEP -1 ControlDelete(TableEnumColumn(TABLE_YearlyStat, nIndex)) END // Clone the new columns NbNewColumns = 5 // we want 5 new columns for example FOR nIndex = 1 TO NbNewColumns // Build the name of the new column NewColumnName = "COL_" + nIndex // Create the new column by cloning ControlClone(COL_Template, NewColumnName) // Modify the header caption of new column {NewColumnName, indControl}..Caption = "Column " + nIndex END // Fill the Table control... // Put your code for filling the table here
Caution: - The columns must be cloned before filling the Table control.
- Two columns cannot have the same name.
Method 2: Creating the columns ControlCreate allows you to create a control without having to use a template. This function can also be used on a column found in a Table control. The new column is automatically added at the end of existing columns. To create a new column: - Create a Table control.
- Clear the content of Table control (TableDeleteAll).
- Delete the previous created columns (ControlDelete).
- Create the new columns (ControlCreate).
- Fill the Table control with data.
Code example:
NewColumn is Control NbFixedColumns is int NbNewColumns is int NewColumnName is string // Clear the table TableDeleteAll(TABLE_YearlyStat) // Delete the previous created columns NbFixedColumns = 3 // for example, 2 fixed columns + the column to create FOR nIndex = TableCount(TABLE_YearlyStat, toColumn) TO NbFixedColumns STEP -1 ControlDelete(TableEnumColumn(TABLE_YearlyStat, nIndex)) END // Create the new columns NbNewColumns = 5 // we want 5 new columns for example FOR nIndex = 1 TO NbNewColumns // Build the name of the new column NewColumnName = TABLE_YearlyStat.Name + ".COL_" + nIndex // Create the new column by creation NewColumn <- ControlCreate(NewColumnName, typColumn) // Modify the header caption of new column NewColumn.Caption = "Column" + nIndex END // Fill the Table control... // Put your code for filling the table here
Caution: - The columns must be created before filling the Table control.
- Two columns cannot have the same name.
Two methods can be used to handle the created column:
This page is also available for…
|
|
|
|