ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / How to proceed? / Programming
  • Overview
  • Method 1: Cloning columns
  • Method 2: Creating the columns
  • Using the new column
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
How to clone and use columns in a Table control?
Overview
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:
  1. Create a Table control.
  2. In the Table control, define the column that will be used as "template for cloning".
  3. Clear the content of Table control (TableDeleteAll).
  4. Delete the previous cloned columns (ControlDelete).
  5. Create the new columns (ControlClone).
  6. 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:
  1. Create a Table control.
  2. Clear the content of Table control (TableDeleteAll).
  3. Delete the previous created columns (ControlDelete).
  4. Create the new columns (ControlCreate).
  5. 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.
Using the new column
Two methods can be used to handle the created column:
Minimum version required
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/27/2022

Send a report | Local help