Jump to content
xorpas

Adding a Custom Icon to a FireMonkey combobox

Recommended Posts

I need a way to dropdown combobox with icon and text  in firemonkey  like this one

 

delphi-240ppi-96.png.930a09a31fe5970cecadfc3a1cd34ade.png

 

Share this post


Link to post

You can add TListBoxItem controls to TComboBox, for example:

procedure TForm1.AddComboBoxItem(const AText: String; const AImageIndex: Integer);
var
	LItem: TListBoxItem;
begin
	TComboBox1.BeginUpdate;
    LItem := TListBoxItem.Create(TComboBox1);
    LItem.Parent := TComboBox1;
    LItem.Images := TImageList1;
    LItem.ImageIndex := AImageIndex;
    LItem.Text := AText;
    TComboBox1.EndUpdate;
end;

TComboBox will use these exactly the same if you were to put strings in TComboBox.Items.

LItem.Images is a property to which you assign a TImageList control, in which you can add images. By assigning LItem.ImageIndex, you will then use the image you defined at that index inside the TImageList.

 

Another option is to define an FMX style in TStyleBook and directly put the image there, but that might be redundant for this specific scenario. Unsure of which approach is better in general, but I prefer the latter one as it is more convenient to use in multiple places. Really depends on what you need though.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×