views:

162

answers:

2

You can easily achieve a multicolumn effect in a listbox by setting the TabWidth property of TListbox. For example, http://delphi.about.com/cs/adptips2000/a/bltip1200_3.htm

I need to do the same in the drop down list of a ComboBox, but comboboxes don't publish any TabWidth property.

Any ideas?

A: 

From what I know there is not so simple way as TabWidth here but you can override Paint method and draw it yourself. Looking at listbox and combobox sources may help.

I think OnDrawItem method would be more useful
SimaWB
I'm wondering why I must do that when the required functionality already exists on a listbox.
PA
+1  A: 

In a comment to this answer advising you to owner-draw the list box items you say:

I'm wondering why I must do that when the required functionality already exists on a listbox

A combo box is actually composed of three native child windows - the combo box itself, an embedded edit, and a list box. You can use the GetComboBoxInfo() function to fill a COMBOBOXINFO structure (i.e. a TComboBoxInfo record) with information about the control, and it will return the 3 HWND elements in it. With that you are able to alter the appearance and behaviour of the list box. In principle.

For the list box to use the tab stops it needs to have the LBS_USETABSTOPS style flag set. Unfortunately this can't be turned on later, the list box has to be created with it. So you could use the functionality only if you were able to turn the style flag on for the list box, which is created during the CreateWindowEx() call for the combo box. AFAICS this can only be done by hooking the CreateWindowEx() call itself, identifying the internal call that creates the list box, and altering the passed style. This means runtime modification of code, and not in your executable but in a Windows DLL.

Owner-drawing the list items looks like it would be much easier.

mghie
Thanks for your complete and detailed explanation that completely answers my question. However it's far too much effort to do it.
PA