Programming Guide : Working with Arrays, Table Fields, and Collections : Table Field Operations : Column Operations
 
Share this page          
Column Operations
This section describes the following operations that affect one or more columns in a table field:
Displaying and removing column headers
Formatting a multiline header
Using hidden columns
Turning CellAttributes on
Using the HasDataChanged attribute
How You Can Display and Remove Column Headers
By default, OpenROAD puts a table header on each table field that you create. This area contains the column titles. You can remove the table header and, consequently, the column titles, by setting the HasHeader attribute of the TableField object to FALSE:
field(tablefield).HasHeader = FALSE
If the table header has been removed and you want to display it, set the HasHeader attribute to TRUE.
How You Can Format a Multiline Header
If you want the title of a column to appear on multiple lines, use the OpenROAD system constant for a new line, HC_NEWLINE. For example, the following statement results in a two-line column title:
field(movie[*].director).title = 'Director''s' +
    HC_NEWLINE + 'Name';
The result looks like this:
Director's
Name
How You Can Use Hidden Columns
Hidden columns are columns in a table field that are invisible to the user. They have a variety of uses, for example, as recordkeeping or status fields.
There are two ways to implement hidden columns:
Set the bias of the column(s) to FB_INVISIBLE.
You may want some table field columns to be visible to some users but not others or invisible only some of the time. For example, it might be acceptable for a supervisor to see a salary column but unacceptable for a clerk to see that information. To change a column to invisible, set the CurBias attribute of the ColumnField object to FB_INVISIBLE.
The following code in a frame's initialize section determines who is using the application and sets the CurBias attribute for the columns in the frame's table field accordingly:
select  :user_name = dbmsinfo('username'),
        :dba_name = dbmsinfo('dba');
commit;
if user_name != dba_name then
    field(custtable[*].acctbal).CurBias =
    FB_INVISIBLE;
Use this strategy only if you want to change the visibility of the column during the running of frame, since it adversely affects performance.
Define a user class that contains hidden columns and those displayed in the table field.
This is the most efficient way to implement hidden columns. This way is useful for keeping a record of data that might be changed by the user.
How You Can Turn CellAttributes On
The CellAttribute object gives you access to the attributes of an individual cell in a table field column. Because of the impact on performance, OpenROAD does not automatically create CellAttribute objects when you create a table field. Instead, if you want to use CellAttribute objects, you must explicitly or implicitly turn them on.
CellAttribute objects are turned on by column rather than on a cell-by-cell basis. Turning on CellAttributes for a column sets it on for all cells in that column.
The easiest way to turn on CellAttributes for a column is to use the Property Inspector to set the column's HasCellAttributes attribute to TRUE. This involves the least performance overhead. However, you can choose to turn CellAttributes on at runtime by using one of the following techniques:
Explicitly, in the initialize portion of a frame script
To turn on the CellAttributes explicitly, set the HasCellAttributes attribute of the ColumnField object to TRUE. The syntax is:
field(tablefield[*].column).HasCellAttributes = TRUE
Implicitly, by referencing one of the CellAttribute's attributes in your script
If they are not already on, the CellAttributes are implicitly turned on when your script sets a cell attribute for a cell. For example, the following event block changes a cell's background color to red when a user tabs into a column. The first time the user enters the specified column, the cell attributes are turned on for that column.
on childentry custtable[*].custname =
begin
    field(custtable[].custname).bgcolor = CC_RED;
end;
Setting CellAttributes implicitly has the advantage of creating CellAttributes only when needed. You cannot turn on CellAttributes for the cells of a nested table field.
How You Can Use the HasDataChanged Attribute
If cell attributes are turned on for a given column field, you can fetch the CellAttribute object for a cell by using the column field CellAttribute method. The following example shows the syntax for fetching the CellAttribute object that corresponds to the cell in a column field:
cellattribute = columnfield.CellAttribute(record = integer)
integer
Specifies the row index of the cell
Having fetched the CellAttribute for a cell, you can use its HasDataChanged attribute to see whether the user has made any changes to the data in the cell. The HasDataChanged attribute is:
TRUE if the user types in an entry field cell or changes a cell of any other type
FALSE when the value of the cell is changed by a 4GL script
A 4GL script can also set the HasDataChanged attribute of a CellAttribute, a column field, or an entire table field. For example, you might set HasDataChanged to FALSE after processing changes.
If you intend to use this attribute, ensure that its information is accurate by turning on the cell attributes explicitly in either of these ways:
In the Property Inspector when you create the frame
By setting the HasCellAttributes attribute when the frame is initialized at runtime