Jump to content
dummzeuch

Setting the drop down width of a Combobox in Delphi

Recommended Posts

Posted (edited)

By default, the width of the drop down list of a TComboBox is the same as the width of the control itself, and even in the latest Delphi version there apparently is no property to set it.

combobox-normal.png.43bb050c66db02a19aa72f1762259df3.png

Why is that so? Good question. There are probably many third party controls that offer this because it is rather simple to implement. But on the other hand, if it is that simple, why isn’t it a feature of the default control? It can really be a pain in the lower back that some entries are just not displayed correctly as seen in the picture above.

Setting the drop down width is as simple as sending the CB_SETDROPPEDWIDTH message to the control’s handle:

1 SendMessage(TheCombobox.Handle, CB_SETDROPPEDWIDTH, MinimumWidthInPixels, 0);

combobox-250.png.53f74b0fec62d0bfba06bf5c64909c29.png

It does not allow to shrink the width of the drop down list though, because it sets the minimum width, not the actual width. There is this answer on StackOverflow for that particular problem. The result isn’t very visually appealing though, because the list is left aligned rather than right.

combobox-50.png.e00676301fd353fd423ef1b391f789f2.png

 

Read on in my blog post

https://blog.dummzeuch.de/2019/06/22/setting-the-drop-down-width-of-a-combobox-in-delphi/

Edited by dummzeuch
pictures didn't work
  • Like 1

Share this post


Link to post

In most cases the widened list is of only limited benefit when the selected item doesn't fit into the edit field either.

Share this post


Link to post
50 minutes ago, Attila Kovacs said:

because VCL is abandoned

hm. No. .. ? Why should it be?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×