Listbox column widths and scrollbar

At run time, if I add or remove a column, I do it by emptying the list and setting the column count.
Then I need to ensure that the columns have a width

It would be good to get the horizontal scrollbar to appear if the combined widths are too great

My problems at the moment:

After changing the columns and adding data, if I iterate through the columns and set a width of (say) 100 for narrow columns, then invalidate, nothing changes.
And even if the new combined widths are ‘too big’ to display, I never see the scrollbar

How best to set new column widths after changing the column count?

Hack:
Listbox.Width = Listbox.Width - 1
Listbox.Width = Listbox.Width + 1

Maybe this helps.

Nope.
Nothing I have tried so far has succeeded in getting the scrollbars to appear and work

In API1, it seems automatic. (I added some columns in the IDE to a current project and set the widths to 100 for all 6 columns; the window width is > 500 pixels)
At run time I get the horizontal scrollBar (the property is Show if needed, of course).

I recall this is not the case if you use * or % in the ColumnWidths string.

API2:
http://documentation.xojo.com/api/deprecated/listbox.html#listbox-hashorizontalscrollbar

That doesnt work for me either. very frustrating.

I found a solution from 2018
Astonishingly, it was one of Emile’s !

It transpires that no matter WHAT you do to a list box, that horizontal bar will never appear unless you change the columnwidths string property to something which is full of specific values.

WHAT ? :wink: (joke)

No, I only do not searched that in the LR (by fear to not found it).

Also, depending on how you set the column widths, your column resizing experience will change (resizing a Column in the middle just resize that column OR have a side effect on other column(s)).
One have to check (what I wrote above) to really understand / sorry if I am not crystal clear.

Now, when I think of it, ‘*’ (and ‘%’ ?) means “variable column value”, so the ListBox width is always larger than all column widths…

I found it; here’s the first part, more paragraph to read (LR from 2015r1):

Resizing Columns
There are two “modes” for column resizing. There is no formal mode property. Rather, the “mode” is implicitly set according to whether every column width is specified as an absolute amount. If you specify all columns either in pixels or as a percentage, you will be using the second mode. If you use an asterisk or leave a column width blank, you will be using the first mode.

After reading the above, I came to the following solution (a 1 column example) to dynamically set the column width to the longest string:

dim w as Integer

ListBox1.RemoveAllRows

if (UBound(App.myFiles) >= 0) then
  w = 0
  for i as Integer = 0 to UBound(App.myFiles)
    ListBox1.AddRow App.myFiles(i)
    if ((7 * len(App.myFiles(i))) > w) then
      w = (7 * len(App.theFiles(i)))
      ListBox1.ColumnWidths = str(w)
    end if
  next
end if
1 Like