Machado
Machado

Reputation: 14489

How can I programatically add an image inside a TListBoxItem?

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?

Upvotes: 1

Views: 594

Answers (1)

Uwe Raabe
Uwe Raabe

Reputation: 47694

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.

Upvotes: 3

Related Questions