dummzeuch 1517 Posted June 22, 2019 (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. 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); 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. Read on in my blog post https://blog.dummzeuch.de/2019/06/22/setting-the-drop-down-width-of-a-combobox-in-delphi/ Edited June 22, 2019 by dummzeuch pictures didn't work 2 1 Share this post Link to post
Markus Kinzler 174 Posted June 22, 2019 22 minutes ago, Attila Kovacs said: because VCL is abandoned No it isn't. Share this post Link to post
Uwe Raabe 2064 Posted June 22, 2019 In most cases the widened list is of only limited benefit when the selected item doesn't fit into the edit field either. 1 Share this post Link to post
Daniel 417 Posted June 22, 2019 50 minutes ago, Attila Kovacs said: because VCL is abandoned hm. No. .. ? Why should it be? 1 Share this post Link to post
KodeZwerg 54 Posted January 31, 2023 Many thanks! Was searching for a solution and yours is exactly matching my needs @dummzeuch Share this post Link to post
Stompie 2 Posted October 5, 2023 In Delphi 11.2 (maybe also in earlier versions), I have noticed that there now is the property "AutoDropDownWidth" on "TComboBox" to do this. 1 1 Share this post Link to post
JohnLM 22 Posted October 11, 2023 In Delphi 11.2, you can change the ComboBox dropdown width using: .DropDownWidth := width, but it is also in the Object Inspector window. And, .AutoDropDownWidth is a boolean, and also in the Object Inspector window. If true, then the width of the cbx will be whatever is the largest text inside the dropdown. When set to false (which is its default), the standard default width is used. 1 Share this post Link to post
David Heffernan 2353 Posted October 11, 2023 What's especially awesome about the VCL code is that it writes the for loop in a really weird way as for var I: Integer := 0 to -1 + Items.Count do with the -1 before the count, and that seems to have taken from Setting the drop down width of a Combobox in Delphi – twm's blog (dummzeuch.de) which in turn is taken from Sizing the ComboBox Drop Down Width (thoughtco.com) Share this post Link to post
Anders Melander 1815 Posted October 11, 2023 22 minutes ago, David Heffernan said: What's especially awesome about the VCL code is that it writes the for loop in a really weird way as for var I: Integer := 0 to -1 + Items.Count do with the -1 before the count, and that seems to have taken from Setting the drop down width of a Combobox in Delphi – twm's blog (dummzeuch.de) which in turn is taken from Sizing the ComboBox Drop Down Width (thoughtco.com) THeY fouND tHe cOdE On ThE InTeRwebS. It muST be ThE beSTESt! 4 Share this post Link to post
dummzeuch 1517 Posted October 11, 2023 So, why is that a problem? Is the code wrong? Or is it just not the way you would have written it? Share this post Link to post
Stefan Glienke 2019 Posted October 11, 2023 (edited) Not so fast - it more likely was some AI that learned it from those sources - soon all loops will be written that way! 5 minutes ago, dummzeuch said: So, why is that a problem? Is the code wrong? Or is it just not the way you would have written it? The problem is that apparently whoever implemented it that way in the VCL did not even care to apply their style guide to the code. And I am not even going into the legal ramifications of Embarcadero copying code from the internet and then putting it under their copyright. Edited October 11, 2023 by Stefan Glienke 1 Share this post Link to post
David Heffernan 2353 Posted October 11, 2023 6 hours ago, dummzeuch said: So, why is that a problem? Is the code wrong? Or is it just not the way you would have written it? I've never in my life seen it written like that. Sure it works. But when you read it, it's not familiar and so it makes you think about it. Impedence. Patterns matter. 2 Share this post Link to post