ListBox Last Column

I have written a method to automatically adjust column width such that a column is always wide enough to show it’s contents…
however if the summation of the contents is wider than the screen i lose the last column of the listbox.

[code]Public Sub AdjustColumnWidths()
dim r,c as Integer
dim pic as new Picture(1,1,32)
dim g as graphics = pic.Graphics
dim w as integer
dim colmax as integer
dim cw as string = “”
dim colmin as integer = 25
dim rows, cols as integer
dim cc as string

rows = ListCount-1
cols = ColumnCount-1

g.TextFont = TextFont
g.TextSize = TextSize

for c=0 to cols-1 'The last column occupies the remaining space. *
if Heading© = “:” then
colmax = 0
else
colmax = g.StringWidth(Heading©)
for r=0 to rows
cc = Cell(r,c)
w = g.StringWidth(cc)
if w > colmax then colmax = w
next r
if colmax < colmin then colmax = colmin
end if
if colmax <> 0 then
cw = cw + str(colmax+8) + “,”
else
cw = cw + “0,”
end if
next c
cw = left(cw, len(cw)-1) 'trim the extra , *

if sortedColumn > -1 then // the listbox is sorted by a column
if LastIndex > 0 then
sort// sort the listbox data using the current sort settings
end if
end
ColumnWidths = cw

End Sub
[/code]

You need to detect the sum of all the column widths and set listbox.ScrollBarHorizontal as needed.

If you add an additional blank column to the listbox your method works fine with all columns