KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A utility method that resizes List Box columns to an equal width
PRODUCT: 4D | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: July 22, 2011

If you are setting the horizontal size of a list box to grow, only the last column of the list box will grow when the window is resized horizontally. The rest of the column will not be effected. However, it is neccessary in some situation to maintain the size of all column to an equal width after when the window is resized. The following method will help setting the size of all colum in a list box to an equal width:

// Method: AUTO_LISTBOX_COLUMN_RESIZE
// Description
// Resize all columns in a listbox to an equal width
//
// Parameters
// $1 - Pointer to a list box variable
// ----------------------------------------------------


C_POINTER($1;$listbox_abp)
C_LONGINT($l;$t;$r;$b;$i;$size_l;$width_l)

If (Count parameters>=1)

  $listbox_abp:=$1
  OBJECT GET COORDINATES($listbox_abp->;$l;$t;$r;$b)

  ARRAY TEXT($ColNames_at;0)
  ARRAY TEXT($HeaderNames_at;0)
  ARRAY POINTER($ColVars_ap;0)
  ARRAY POINTER($HeaderVars_ap;0)
  ARRAY BOOLEAN($ColsVisible_ab;0)
  ARRAY POINTER($Styles_ap;0)
  LISTBOX GET ARRAYS($listbox_abp->;$ColNames_at;$HeaderNames_at;\
    $ColVars_ap;$HeaderVars_ap;$ColsVisible_ab;$Styles_ap)

  $size_l:=Size of array($ColVars_ap)
  $width_l:=Int(($r-$l)/$size_l)

  For ($i;1;$size_l)
    LISTBOX SET COLUMN WIDTH($ColVars_ap{$i}->;$width_l)
  End for

End if


For example:

  // Form method: Resize all list box columns when the window is resized.
If (Form event=On Resize)
  AUTO_LISTBOX_COLUMN_RESIZE (->List Box)
End if