Search code examples
delphivcldelphi-11-alexandria

How can I add images into a TComboBox in VCL?


I'm trying to have a TComboBox with images instead of text. Is this possible? If yes, then how? I've looked over all of the properties a dozen times and I can't find anything. Also, I'm very new to Delphi. So maybe this is obvious, but I couldn't find a place to add images into a ComboBox instead of text. How can I add images to my ComboBox?

I tried looking online for help, but nothing really helped or nothing that was easy enough for me to understand.


Solution

  • For TComboBox, you can set its Style property to one of the OwnerDraw options, and then use its OnDrawItem event to draw your images.

    Or, as Andreas Rejbrand mentioned, you can use TComboBoxEx instead. Put your images in an ImageList assigned to its Images property, and then assign an ImageIndex to each item in its ItemsEx property.