PC Review


Reply
Thread Tools Rate Thread

ComboBox listwidth to match text in list

 
 
J.S.Winstrom
Guest
Posts: n/a
 
      2nd Aug 2007
I am having some trouble in finding information on how to set the
listwidth/columnwidths in a combobox to match the text longest entry. Any
help would be greatly apreciated!

~J.S.Winstrom
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      2nd Aug 2007
If you want the size of the list box to change with each time chosen that
that is not to bad. Using a combo box from the Control Toolbox change the
AutoFit Property to True.

If you want to set the size of the box to be as long as it need to be for
the longest entry then that is more difficult than it sounds. The problem
arises because by default you are probably using a proporational font like
Tahoma or Arial where the with of each character varies. Based on that it is
very difficult to know which is the "longest" entry and what the required
width is. If you Switch to courier or some other non-proportional font then
you can determine the length of each character based on the font size and
proportion your width accordingly. My suggestion for this is to just make the
Box as big as you reasonably can...
--
HTH...

Jim Thomlinson


"J.S.Winstrom" wrote:

> I am having some trouble in finding information on how to set the
> listwidth/columnwidths in a combobox to match the text longest entry. Any
> help would be greatly apreciated!
>
> ~J.S.Winstrom
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      2nd Aug 2007
autofit the column without wraptext and set the column width to the Width
property of the column. Make sure the fonts and font size are the same.

--
Regards,
Tom Ogilvy

"J.S.Winstrom" wrote:

> I am having some trouble in finding information on how to set the
> listwidth/columnwidths in a combobox to match the text longest entry. Any
> help would be greatly apreciated!
>
> ~J.S.Winstrom
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      2nd Aug 2007
You have completely lost me... Combo Boxes dont' have a wraptext property and
lots of what you discuss just does not seem to fit... I'm probably missing
something?
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

> autofit the column without wraptext and set the column width to the Width
> property of the column. Make sure the fonts and font size are the same.
>
> --
> Regards,
> Tom Ogilvy
>
> "J.S.Winstrom" wrote:
>
> > I am having some trouble in finding information on how to set the
> > listwidth/columnwidths in a combobox to match the text longest entry. Any
> > help would be greatly apreciated!
> >
> > ~J.S.Winstrom
> >

 
Reply With Quote
 
Atomic Storm
Guest
Posts: n/a
 
      2nd Aug 2007
=?Utf-8?B?SmltIFRob21saW5zb24=?=
<James_Thomlinson@owfg-Re-Move-This-.com> wrote in
news:70D5CC83-CECC-4AC9-9D0A-(E-Mail Removed) on Thu 02 Aug
2007 12:58:07p:

> You have completely lost me... Combo Boxes dont' have a wraptext
> property and lots of what you discuss just does not seem to fit... I'm
> probably missing something?


Seems I haven't explained this correctly. I how to set the combobox width
through the properties using autosize = true - however, I am looking to set
the .listwidth and .columnwidths of the dropdown list via the largest text
(listindex) entry. Something like:

Dim getCount as String
getCount = ComboBox1.ListCount
For iNum = 0 to getCount
With ComboBox1
.ListWidth = .List(iNum).Width
End With
if iNum = getCount - 1 then Exit For
Next i

Which doesn't quite work... I tried it.

Hopefully that's a little more clear of what I'm after

Thanks for the input!

~J.S.Winstrom
 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      2nd Aug 2007
this is untested and i'm not sure if it's even what you want.

once the combobox is populated, this would run and create an array of the length
of each entry:

For z = 0 To ComboBox1.ListCount - 1
arr(z) = Len(ComboBox1.List(z))
Next

then:
Application.Max(arr)

would return the element with the length of the longest entry
maybe you can use that to set the width, not sure what you want.


--


Gary


"Atomic Storm" <(E-Mail Removed)> wrote in message
news:Xns9980879E765E1jgwinstrommicrosoft@207.46.248.16...
> =?Utf-8?B?SmltIFRob21saW5zb24=?=
> <James_Thomlinson@owfg-Re-Move-This-.com> wrote in
> news:70D5CC83-CECC-4AC9-9D0A-(E-Mail Removed) on Thu 02 Aug
> 2007 12:58:07p:
>
>> You have completely lost me... Combo Boxes dont' have a wraptext
>> property and lots of what you discuss just does not seem to fit... I'm
>> probably missing something?

>
> Seems I haven't explained this correctly. I how to set the combobox width
> through the properties using autosize = true - however, I am looking to set
> the .listwidth and .columnwidths of the dropdown list via the largest text
> (listindex) entry. Something like:
>
> Dim getCount as String
> getCount = ComboBox1.ListCount
> For iNum = 0 to getCount
> With ComboBox1
> .ListWidth = .List(iNum).Width
> End With
> if iNum = getCount - 1 then Exit For
> Next i
>
> Which doesn't quite work... I tried it.
>
> Hopefully that's a little more clear of what I'm after
>
> Thanks for the input!
>
> ~J.S.Winstrom



 
Reply With Quote
 
J.S.Winstrom
Guest
Posts: n/a
 
      2nd Aug 2007
"Gary Keramidas" <GKeramidasATmsn.com> wrote in
news:(E-Mail Removed) on Thu 02 Aug 2007 01:37:20p:

> this is untested and i'm not sure if it's even what you want.
>
> once the combobox is populated, this would run and create an array of
> the length of each entry:
>
> For z = 0 To ComboBox1.ListCount - 1
> arr(z) = Len(ComboBox1.List(z))
> Next
>
> then:
> Application.Max(arr)
>
> would return the element with the length of the longest entry
> maybe you can use that to set the width, not sure what you want.
>
>


I don't know about the Application.Max(arr), but would I be able to do a
ComboBox1.ListWidth = arr ?
 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      2nd Aug 2007
Gary - The problem with what you have shown is that len returns the number of
characters, not the sum of the widths of all of the characters. Each
character is a different size.

Atomic - To your question about list width / column width. Unless you choose
a non-proportional font like courier you are going to run into problems. The
width of i and the width of z are very different. If you coose courier then
you can traverse your list of entries an determine the max number of
characters an multiply that by the size of 1 character to determine your
width... My preference is still just to hard code a width that will
accomodate darn near anything.
--
HTH...

Jim Thomlinson


"Gary Keramidas" wrote:

> this is untested and i'm not sure if it's even what you want.
>
> once the combobox is populated, this would run and create an array of the length
> of each entry:
>
> For z = 0 To ComboBox1.ListCount - 1
> arr(z) = Len(ComboBox1.List(z))
> Next
>
> then:
> Application.Max(arr)
>
> would return the element with the length of the longest entry
> maybe you can use that to set the width, not sure what you want.
>
>
> --
>
>
> Gary
>
>
> "Atomic Storm" <(E-Mail Removed)> wrote in message
> news:Xns9980879E765E1jgwinstrommicrosoft@207.46.248.16...
> > =?Utf-8?B?SmltIFRob21saW5zb24=?=
> > <James_Thomlinson@owfg-Re-Move-This-.com> wrote in
> > news:70D5CC83-CECC-4AC9-9D0A-(E-Mail Removed) on Thu 02 Aug
> > 2007 12:58:07p:
> >
> >> You have completely lost me... Combo Boxes dont' have a wraptext
> >> property and lots of what you discuss just does not seem to fit... I'm
> >> probably missing something?

> >
> > Seems I haven't explained this correctly. I how to set the combobox width
> > through the properties using autosize = true - however, I am looking to set
> > the .listwidth and .columnwidths of the dropdown list via the largest text
> > (listindex) entry. Something like:
> >
> > Dim getCount as String
> > getCount = ComboBox1.ListCount
> > For iNum = 0 to getCount
> > With ComboBox1
> > .ListWidth = .List(iNum).Width
> > End With
> > if iNum = getCount - 1 then Exit For
> > Next i
> >
> > Which doesn't quite work... I tried it.
> >
> > Hopefully that's a little more clear of what I'm after
> >
> > Thanks for the input!
> >
> > ~J.S.Winstrom

>
>
>

 
Reply With Quote
 
J.S.Winstrom
Guest
Posts: n/a
 
      2nd Aug 2007
=?Utf-8?B?SmltIFRob21saW5zb24=?=
<James_Thomlinson@owfg-Re-Move-This-.com> wrote in
news:831323C0-D8C0-4AA5-A948-(E-Mail Removed) on Thu 02 Aug
2007 02:22:01p:

> Gary - The problem with what you have shown is that len returns the
> number of characters, not the sum of the widths of all of the
> characters. Each character is a different size.
>
> Atomic - To your question about list width / column width. Unless you
> choose a non-proportional font like courier you are going to run into
> problems. The width of i and the width of z are very different. If you
> coose courier then you can traverse your list of entries an determine
> the max number of characters an multiply that by the size of 1
> character to determine your width... My preference is still just to
> hard code a width that will accomodate darn near anything.


Jim: Thanks again for helping out. The only problem with hard-coding the
length is there is too much of a range in widths. The data loaded into any
given combo in my userform is loaded from an external access database. So
the text length could range from "A" to
"Supercalifragilisticexbeealidocious". So, if I can, I need to figure out a
method or formula of determining the width of the largest entry at any
given time.

Gary: Thanks for the input. Unfortunately, James is right. It returned the
largest number of characters and set the listwidth to 10 points when, in
actuality, it needed to be about 52 points.
 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      2nd Aug 2007
Since you now know the max number of characters set your combo box font to
courier and multiply the characters by approximately 5 (depends on your font
size). This will give you the max width. You can stay with Tahoma or Arial
but you will need to determine your max character size and use that. This
will make the box a bit too large but it is the closest you will get without
a whole pile of work.
--
HTH...

Jim Thomlinson


"J.S.Winstrom" wrote:

> =?Utf-8?B?SmltIFRob21saW5zb24=?=
> <James_Thomlinson@owfg-Re-Move-This-.com> wrote in
> news:831323C0-D8C0-4AA5-A948-(E-Mail Removed) on Thu 02 Aug
> 2007 02:22:01p:
>
> > Gary - The problem with what you have shown is that len returns the
> > number of characters, not the sum of the widths of all of the
> > characters. Each character is a different size.
> >
> > Atomic - To your question about list width / column width. Unless you
> > choose a non-proportional font like courier you are going to run into
> > problems. The width of i and the width of z are very different. If you
> > coose courier then you can traverse your list of entries an determine
> > the max number of characters an multiply that by the size of 1
> > character to determine your width... My preference is still just to
> > hard code a width that will accomodate darn near anything.

>
> Jim: Thanks again for helping out. The only problem with hard-coding the
> length is there is too much of a range in widths. The data loaded into any
> given combo in my userform is loaded from an external access database. So
> the text length could range from "A" to
> "Supercalifragilisticexbeealidocious". So, if I can, I need to figure out a
> method or formula of determining the width of the largest entry at any
> given time.
>
> Gary: Thanks for the input. Unfortunately, James is right. It returned the
> largest number of characters and set the listwidth to 10 points when, in
> actuality, it needed to be about 52 points.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Match Text with List tommcbrny Microsoft Excel Misc 1 27th Jan 2010 12:07 PM
Find closest text match for each unique entry in a list =?Utf-8?B?TmF0aGFuX0RlY2tlcg==?= Microsoft Excel Misc 2 23rd Sep 2007 01:36 AM
ListWidth and ColumnWidths =?Utf-8?B?SVRfcm9vZmVy?= Microsoft Excel Programming 0 31st Jul 2007 05:04 PM
Combobox text not in list strange behaviour =?Utf-8?B?Y2xvcmVudHNvbg==?= Microsoft Dot NET Framework 0 23rd Mar 2005 07:57 PM
ComboBox.ListWidth question Joepy Microsoft Excel Programming 1 5th Sep 2003 04:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.