Cell color attributes

List controllers can display every cell in a specific color.

When using the DISPLAY ARRAY or INPUT ARRAY, you can assign specific colors to cells of a TABLE or TREE rows with the DIALOG.setArrayAttributes() or DIALOG.setCellAttributes() method.

Important: This feature is not supported on mobile platforms.

Call the method in the dialog initialization clause, for example, in BEFORE DISPLAY for a singular DISPLAY ARRAY dialog.

The method takes an array as parameter. This array must have the same structure as the data array, but each element of the record must be a string. Attributes can be set for individual cells by using the TTY attributes (see method reference for possible values).

If cell attribute values are changed in during the dialog execution, use the UNBUFFERED mode to get automatic form synchronization. The unbuffered mode is not required if the cell attributes are defined before executing the dialog, and leave unchanged until the dialog ends.

Example

This is the list.per form file defining the table view:

LAYOUT
TABLE
{
[c1         |c2             ]
}
END
END
ATTRIBUTES
c1 = FORMONLY.key;
c2 = FORMONLY.name;
END
INSTRUCTIONS
SCREEN RECORD sr(FORMONLY.*);
END

This is the program code (main.4gl):

MAIN
    DEFINE arr DYNAMIC ARRAY OF RECORD
               key INTEGER,
               name VARCHAR(100)
           END RECORD
    DEFINE att DYNAMIC ARRAY OF RECORD
               key STRING,
               name STRING
           END RECORD
    DEFINE I INT

    FOR i=1 TO 10
        LET arr[i].key = i
        LET arr[i].name = "Item "||i
        LET att[i].key = "red reverse"
        LET att[i].name = IIF(i MOD 2,"blue","green")
    END FOR

    OPEN FORM f1 FROM "list"
    DISPLAY FORM f1

    DISPLAY ARRAY arr TO sr.* ATTRIBUTES(UNBUFFERED)
        BEFORE DISPLAY
           CALL DIALOG.setCellAttributes(att)
       ON ACTION att_modify_cell 
         LET att[2].key = "red reverse"
       ON ACTION att_clear_cell 
         LET att[2].key = NULL
    END DISPLAY

END MAIN