Search code examples
androiddelphilistviewfiremonkey

FireMonkey TListView: How to color items at runtime?


It is possible to use custom drawing for the VCL TListView, which allows you to colour individual items (here is an example using the rather dodgy approach of putting a TColor in the Data of an item.)

However, in the XE7 FMX version of the TListVew control, there is no OnCustomDraw event. I tried some options, but nothing seems to change the colors. How do I do this?


Solution

  • You can change the color of each list item's text using the TListViewItem.Objects.DetailObject.TextColor property. But there is no native property for changing each list item's background color.

    Accordingly to TListView Items background color:

    How to change the background color of TListView Items?
    ...
    You have to use a style. So add a stylebook en either use one of the styles that come with Delphi or right click the listview "edit custom style"to make the style. dubbleclick on the stylebook to open the style and modify the listviewstyle.

    But that does not explain how to apply a different style to each list item.