ITDevCon 9: ListView and LiveBindings

Today, during my session at ITDevCon 9, I have been hit by the typical “demo effect” and my example about TListView customization and LiveBinding’s CustomFormat functionality refused to work.

Obviously after a good coffee (we are in Italy, right?) and 5 minutes to rebuild my example from scratch, everything works. Who knows what happened.

So I am sharing here my example about two typical functionalities around listviews and databindings:

show an image (glyph) according to some data of the item;

formatting a number as money.

Both are implemented through the use of CustomFormat property. We have a dataset (the “orders” dataset you can find in your Samples\Data folder of RAD Studio/Delphi installation) and a TListView bound to it through LiveBindings technology. The TListView has a dynamic appearance and three drawables in each item: Text1, Text2 (two TTextObjectAppearance objects) and Image3 (a TImageObjectAppearance object). There is a TImageList (linked to the TListView through its Images property) containing a couple of images.

Text1 shows the order number with a fixed ‘Order No.’ prefix.CustomFormat: ‘Order No. ‘ + AsString

Text2 shows the ItemsTotal field value, properly formatted as money.CustomFormat: Format(‘%%m’, Owner.ItemsTotale.AsFloat + 0.0)(the ‘+ 0.0’ is a trick to force the expression to match the required type)

LiveBindings may still need some love but can be very effective in a number of situations and are actually a very powerful mechanism.

Update: someone (Thomas) asked about how to change the TextColor of the drawable showing the ItemsTotal in the ListView depending on some conditions. You can use the OnFillingListItem event of the LiveBinding object (LinkFillControlToField1) and write something like this: