Customizing TComboBox dropdown in FMX

Yesterday a customer asked me about customizing the FMX dropdown in order to make it consistent with the rest of UI. Specifically, we were trying to change the background of the dropdown list to a semitransparent color. Even if this sounded trivial to me at first, it turned out to be a little tricky, hence this blog post (and also the Quality Center issue RSP-36079).

First thing I tried was to customize the TComboBox style and change the background but soon I noticed the background element included was the one defining the combobox background when it’s closed and it has nothing to do with the dropdown list.

After digging a bit around the TComboBox source code, I understood:

  1. a TListBox instance is used internally by TComboBox to render the dropdown list;
  2. I already knew it was possible to customize a TListbox appearance through style;
  3. there is a ListBoxResource property in TComboBox class that is supposed to be the way you drive the style selection (affecting StyleLookup property) of the actual TListBox instance used as dropdown;

The tricky thing is that you also have to set DropDownKind property to Custom to make everything work, otherwise (when DropDownKind = Native) you’ll never see your custom listbox style applied to the dropdown.

The following screenshot shows the combobox with the dropdown list opened. On the left you can see a TListBox instance I’ve used to customize the listbox style in the IDE. You can also notice the combobox and the listbox are actually semi-transparent as I’ve placed a TRectangle instance in the background to emphasize it.

If you look with attention, however, you’ll notice the dropdown is not actually semi-transparent: there’s something in between the styled listbox and the background. It is the Popup the combobx uses to host the listbox. It has its own style (‘combopopupstyle’) that is probably somehow “solid” in the Win10 FMX default style.

You can add a TLayout instance to the TStyleBook instance on your form to override the combopopupstyle definition (just set its StyleName property to ‘combopopupstyle’).

This is the final effect:

Hope this can be useful to others.

Andrea

2 thoughts on “Customizing TComboBox dropdown in FMX

  1. Serge Girard says:

    Hi,
    Interesting. I had a different approach, you can read in my blog (sorry french but googletrad or other can help ;))

    https://www.developpez.net/forums/blogs/138527-sergiomaster/b7012/fmx-combobox-aux-petits-oignons/
    https://www.developpez.net/forums/blogs/138527-sergiomaster/b7086/fmx-combobox-aux-petits-oignons-suite/

    Using a TListview instead of a TListbox offer more possibilities (search)

  2. Scott says:

    Andrea,
    Thanks for this post., Helpful.

    Would you happen to know how detect that the user has made a selection from a TComboBox (or in my case, TComboEdit)? In VCL it is straightforward as there is an osSelect event, but I can’t find an equivalent in FMX Mac OS.

    Thank you for any help you can provide.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.