Search code examples
delphicomboboxdelphi-7separator

Creating a ComboBox with one or more separator items?


I'm using Delphi7 and I'd like to have a ComboBox with separator items (Just like in popup menus).

I've seen this beautifully implemented in Mozilla Sunbird (I know, it's not Delphi...) the following way:

  1. The separator item is a simple gray line drawn in the center of the item

  2. If you hover over the separator with the mouse, the selection doesn't appear

  3. If the user clicks the separator, it's not selected either AND the combobox doesn't closeup.

No. 1 could be implemented using DrawItem. I could live without No. 2 because I have no idea about that.

For No. 3 I'm asking for your help. I've figured out that straight after closing up a CBN_CLOSEUP message is sent to the combobox.

I thought about hooking the window proc and if CBN_CLOSEUP is sent to a certain combobox then countering it. But I'm unsure if this is the best solution, or maybe there are other, more elegant ways?

Whatever the solution is, I'd like to have a standard ComboBox which supports WinXP/Vista/7 theming properly.

Thanks!


Edit: For a working component please see this thread:

Can you help translating this very small C++ component to Delphi?


Solution

  • What you want is an owner-drawn combobox. See this: http://delphi.about.com/od/vclusing/a/drawincombobox.htm

    Also, this seems to solve making the item unclicable: http://borland.newsgroups.archived.at/public.delphi.vcl.components.using.win32/200708/0708225320.html

    As far as I know there is no VCL way of doing that, so you'll have to subclass the combobox. It would be nice to create component encapsulating those functionalities so you can reuse them easily.

    God bless