Search code examples
delphicomboboxvcltcombobox

How does TComboBoxEx in VCL work to add images in it?


I'm trying to add images into a combobox instead of text. Someone recommended I use the TComboBoxEx instead of TComboBox, but how does it work?

I found a tutorial, but it's confusing and I do not understand. Does it work different than normal ComboBox? https://docwiki.embarcadero.com/CodeExamples/Alexandria/en/TComboBoxEx_(Delphi)

With TComboBox, there's a TStrings Items property that I can use to change the text.

I do not see a Items property for TComboBoxEx.

How can I have images for a dropdown instead of Text?


Solution

  • You can use the ItemsEx property to add text and images. Double clicking on ItemsEx opens this window:

    Delphi Edit ComboBoxEx ItemsEx

    From there with the top-left button, you can add dropdown items and then you'll see a Caption and ImageIndex for each item:

    Delphi Edit ComboBoxEx ItemsEx

    The images are populated through a TImageList component that you have to drop onto the form as well and then there's an Images property on the TComboBoxEx that you have to set equal to the TImageList

    And that's it. Then you have your ComboBox with images:

    Delphi TComboBoxEx