|
-
Apr 25th, 2011, 04:58 AM
#1
Thread Starter
Frenzied Member
Combo Box dropdown - Excel Form
What's the best way to set ListWidth to fit the longest entry in the list?
Many thanks, ABB
-
Apr 25th, 2011, 04:03 PM
#2
Hyperactive Member
Re: Combo Box dropdown - Excel Form
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
-
Apr 25th, 2011, 10:35 PM
#3
Re: Combo Box dropdown - Excel Form
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
vb 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
as there is no textwidth in vba, just adjust the width until you get the best results, test with different fonts to suit
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
Last edited by westconn1; Apr 25th, 2011 at 10:38 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|