What's the best way to set ListWidth to fit the longest entry in the list?
Many thanks, ABB
Printable View
What's the best way to set ListWidth to fit the longest entry in the list?
Many thanks, ABB
Never tried it, but it looks like there is an autofit property, and you may have to change the font type for the combobox.
http://www.eggheadcafe.com/software/...t-in-list.aspx
if you are adding in a loop, you can check the lengths to get the longest as you add
else you can loop through the list to get the longest
as there is no textwidth in vba, just adjust the width until you get the best results, test with different fonts to suitvb Code:
For i = 1 To 20 s = "item " & i ^ i If Len(s) > Len(l) Then l = s ListBox1.AddItem s Next ListBox1.Width = Len(l) * ListBox1.Font.Size / 1.5
contents of wwwww are likely to be considerably wider than iiiii, so some adjustment may also be required to allow for more or less wide characters than of average strings
there would be APIs that would give much more precise results if you want to go that way