KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Simulating list box headers for more control
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: April 7, 2011

List box headers contain an image that is displayed in the background, which is not editable. There may be situations where it would be desirable to change the background image. In these cases, there is a workaround.

In order simulate a list box header that has a different image or color, place another object on top of the list box headers to act as the header.

This solution would consist of placing an object, such as a picture variable, over each list box header, and then setting the image for that object. Note, in this case, the header title would need to be included in the image.

Also, if you just want a solid color background, then a text variable could be used. The variable's background color can be set using the Property List or programmatically using OBJECT SET COLOR or OBJECT SET RGB COLORS.

When using this solution, additional attention would need to be taken in regards to sorting and resizing, since the actual list box header objects will not be used.

Sorting - In order to achieve sorting for each header, use the command LISTBOX SORT COLUMNS. This command would be placed within the each header's object method and within the "On Clicked" event context.

Resizing - Ideally, when using this solution, resizing of the list box columns would be disabled. However, if resizing is required, then this can be solved using the list box column's On Column Resize event. In the object method you would add code to do the following:

  • Use the command OBJECT GET COORDINATES to get the coordinates of the actual list box header objects after they have been resized, and the coordinates of the replacement header objects

  • Calculate the distance that each header will need to be moved and/or resized

  • Use the OBJECT MOVE command to resize and/or move the replacement header objects appropriately