Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Autosizing listbox columns


Message #1 by martin.scullion@u... on Fri, 31 Jan 2003 12:59:06
I have a listbox on my form, it is split into multiple columns. The data 
for each column is of a variable length, how do I size the columns so that 
the data fits without being truncated.

Message #2 by "Gregory Serrano" <SerranoG@m...> on Fri, 31 Jan 2003 13:35:05
<< I have a listbox on my form, it is split into multiple columns. The 
data for each column is of a variable length, how do I size the columns so 
that the data fits without being truncated. >>

If you're asking how to change the widths of the listbox columns, use 
the .ColumnWidths property to set the widths.

If you're asking, how to adjust the column widths "on the fly" so that 
whatever ends up on a changing list still fits on the column listing, then 
that takes coding.  There's no "size to fit" option for the .ColumnWidths 
property.

Not having done this, my first guess is to find the longest word on your 
list using LEN(), and then apply an estimate to the .ColumnWidths 
property.  For example, suppose you want to establish that for each ten 
letters of a word, you want one inch of column width, then try:

   1) Read the items on the list.
   2) Find the longest item using LEN() function.

   Me.lstMyList.ColumnWidths = Round(Length of Longest Item1 / 10) & _
   " in; " & Round(Length of Longest Item2 / 10) & " in; " & ...

If you don't supply a second argument in the ROUND function, it gives you 
an integer.  If you're worried about very wide columns, you can reset the 
column width to a max if Round(Len(Item)/10) > max.

Greg




  Return to Index