How can I programatically add an image inside a TL

2019-08-13 10:29发布

问题:

Problem

For a long time, I was using a Custom Style to load a detailed TListBox.

It's basically a ListBox with a TImage as an icon.

However recently I've been encountering lots of bugs and decided to throw it all away.

This is how I generate my TListBox items programatically:

   // Create LISTBox Item
   lb_item        := TListBoxItem.Create(self);
   lb_item.Parent := lb_awesome_list;
   lb_item.Text   := cow_name;

What if I would like to add an Image to it?

What I have done so far

I've tried to add it as an ItemData

lb_item.ItemData.Bitmap := iv_user_ic.Bitmap;

And a few other options without success. Is it possible to add an image programatically?

回答1:

The approach with setting the ItemData.Bitmap property is a good start. Now you have to select an appropriate item style to show the bitmap. F.i. listboxitemleftdetail should do.