Listbox columnwidths with horizontal anchor both (1 Viewer)

Martin Beney

Registered User.
Local time
Today, 13:24
Joined
Mar 22, 2007
Messages
27
Hi,
I can't seem to find any help on this issue on the net.

I have a multi-column listbox and have set horizontal anchor to both.

The listbox is widened but the columns stay the same width. Accessing the width of the listbox at run time only returns the designed width not the current actual width.

So, how do you stretch the columns in this scenario?

Regards
Martin
 

Ranman256

Well-known member
Local time
Today, 03:54
Joined
Apr 9, 2015
Messages
4,339
column widths are not dynamic. Manually set them in COLUMNWIDTHs property.
 

Martin Beney

Registered User.
Local time
Today, 13:24
Joined
Mar 22, 2007
Messages
27
Found a solution. Yes you can change columnwidths in code the problem was to find the values to use.

I eventually found that a Form's InsideWidth always returns the expanded width whilst a Form's Width returns the design width. So a simple ratio can be used to change the column widths of a list box.

The following subroutine seems to work fine. BUT it has only been tested on a couple of forms. Please reply if you find a bug!

Regards
Martin

Public Sub prorateColumnWidths(aForm As Access.Form, aListBox As Access.ListBox)

Dim i As Integer, j As Integer
Dim oldWidths As String
Dim newWidths As String
Dim wWidth As Long

If aListBox.HorizontalAnchor = acHorizontalAnchorBoth Then
oldWidths = aListBox.ColumnWidths
i = 1
Do
j = InStr(i, oldWidths, ";")
If j = 0 Then j = Len(oldWidths) + 1
wWidth = Val(Mid$(oldWidths, i, j - i))
wWidth = wWidth * aForm.InsideWidth / aForm.Width
newWidths = newWidths & ";" & wWidth
i = j + 1
Loop Until i > Len(oldWidths)
aListBox.ColumnWidths = Mid$(newWidths, 2)
End If

End Sub
 

Users who are viewing this thread

Top Bottom