How Do I Change the Number Format of a Column by Script?

This lesson describes, how, once a datagrid is installed in a project, developpers can continue changing the number format of a specific column without DGH.

This allow for example, the creation of a preferences dialog where the final user can set is format.

What Are the Custom Properties Added by DGH for Formatting Columns?

DGH adds a special custom property named dgh_FormatColumn in the datagrid group.

This custom property contains an array of two dimensions:

1. the first dimension is a column name.

2. the second dimension is the name of one of the three following format properties:

- pattern

- thousand sep

- dec sep

How Do I Can Get The Column Number Format?

To read the format applied to a column, you can use the following code:

function readColumnFormat pTheDatagridName, pTheColumnName

local tData, tThePattern, tTheThousandSep, tTheDecSep

put the dgh_FormatColumn of group pTheDatagridName into tData

put tData[pTheColumnName]["pattern"] into tThePattern

put tData[pTheColumnName]["thousand sep"] into tTheThousandSep

put tData[pTheColumnName]["dec sep"] into tTheDecSep

return tThePattern & cr & tTheThousandSep & cr & tTheDecSep

end readColumnFormat

Where:

pTheDatagridName is the datagrid name

pTheColumnName is a column name

Example:

put readColumnFormat("datagrid 1", "numbers")

How Do I Can Set The Column Number Format?

To apply a number format to a column, you can use the following code:

command writeColumnFormat pTheDatagridName, pTheColumnName, pThePattern, pTheThousandSep, pTheDecSep

local tData

 

put the dgh_FormatColumn of group pTheDatagridName into tData

put pThePattern into tData[pTheColumnName]["pattern"]

put pTheThousandSep into tData[pTheColumnName]["thousand sep"]

put pTheDecSep into tData[pTheColumnName]["dec sep"]

set the dgh_FormatColumn of group pTheDatagridName to tData

send "refreshList" to group pTheDatagridName

end writeColumnFormat

Where:

pTheDatagridName is the datagrid name

pTheColumnName is a column name

pThePattern is a pattern

pTheThousandSep is the thousands separator

pTheDecSep is the decimal separator

Example:

writeColumnFormat "datagrid 1", "numbers", "$### ##0[green],$### ##0[red]",",","."

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.