Creating a ComboBox with one or more separator items?

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-12-04T17:46:39Z Indexed on 2014/08/25 16:20 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about combobox