KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to set Background color of a List Box cell and stay in sync with Alternate Background Color
PRODUCT: 4D | VERSION: v16, v15, v14, v13 | PLATFORM: Mac & Win
Published On: September 21, 2016

It is always a help to draw the users attention to outliers of data in a list box. One way to do this is to use a different background color for the cell that contains the outlieing data. Because most list box implementations use "Alternate Background Color" to help the user with eye control as they scan acros a row, the task is how to honor the alternate background color and applying outlier colors.



To apply a custom background color at the cell level a project method has to be installed in the column property Row Background Color, highlighted in yellow below. The property accepts a 4D Expression. The 4D Expresison is a project method, SubTotalColorize, is highlighted in green and the two parameters are highlighted in purple. SubTotalColorize is called for every row as it is about to be rendered the list box, even when being sorted by a click in a header.



The first parameter [INVOICES]Subtotal and the second parameter is the Selected record number, which will match the row number being added to the list box.

To honor the Alternate Background Color, its hex value must be captured for use in the SubTotalColorize project method. This can be done using the color picker that can be invoked by clicking in the second column of the property.



The code for the SubTotalColorize project method is shown below. When the Case of tests falls to Else the row number is tested for its evenness. If it is odd the standard background is returned, in this example, white. If the row number is even the Alternate Background Color is returned.