PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 sample:
NbFixedColumns is int
NbNewColumns is int

sNewColumnName 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 nSub = TableCount(TABLE_YearlyStat,toColumn) TO NbFixedColumns STEP -1
ControlDelete(TableEnumColumn(TABLE_YearlyStat, nSub))
END

// Clone the new columns
NbNewColumns = 5 // we want 5 new columns for example
FOR nSub = 1 TO NbNewColumns
// Build the name of new column
sNewColumnName = "COL_"+nSub
// Create the new column by cloning
ControlClone(COL_Template, sNewColumnName)

// Modify the header caption of new column
{sNewColumnName, indControl}..Caption = "Column " + nSub

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 sample:
NewColumn is Control

NbFixedColumns is int
NbNewColumns is int

sNewColumnName 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 nSub = TableCount(TABLE_YearlyStat, toColumn) TO NbFixedColumns STEP -1
ControlDelete(TableEnumColumn(TABLE_YearlyStat, nSub))
END

// Create the new columns
NbNewColumns = 5 // we want 5 new columns for example
FOR nSub = 1 TO NbNewColumns
// Build the name of new column
sNewColumnName = TABLE_YearlyStat..Name + ".COL_"+nSub
// Create the new column by creation
NewColumn <- ControlCreate(sNewColumnName, typColumn)

// Modify the header caption of new column
NewColumn..Caption = "Column " + nSub
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 required version
  • Version 22
This page is also available for…
Comments
Click [Add] to post a comment