What is the API 2 Replacement for .ColumnWidth(i)

Hello,

In using list boxes before I started out with an estimated size for each column, then did some math and adjusted each columns width.

This is the code pre API 2
lstSiteMaster.ColumnWidth(i)

What is the replacement?? If none, then how to perform the same tasks?
Thank you,
Tim

Look up ColumnWidths in the DesktopListbox doc. It’s a String.

Hi Tim,

This is for Web not desktop…

Roger that. I always find the last post date and the Targets etc stuff to be near invisible so I tend not to notice it.

1 Like

You can calculate all columns widths and use .ColumnWidths to assign the values as a comma separated string.

You can create an Issue asking to bring back .ColumnWidth(i) to WebListbox.

There is a Feature Request for being able to set individual column widths in WebListBox:
Issue #69042

Yes, I asked for it almost a year ago…
Tim

1 Like

Sorry Tim, I didn’t realize it was you.

Our idea is to use ColumnsAttributesAt, like in DesktopListBox.

But in the meantime, you can use Extends to bring back ColumnWidth. It should be something similar to this, adapt if needed.

Create a Module and add these two global methods:

Getter:

Public Function ColumnWidth(Extends listbox As WebListBox, column As Integer) As String
  Var widths() As String = listbox.ColumnWidths.Split(",")
  
  While widths.Count < listbox.ColumnCount
    widths.Add("*")
  Wend
  
  Return widths(column)
End Function

Setter:

Public Sub ColumnWidth(Extends listbox As WebListBox, column As Integer, Assigns value As String)
  Var widths() As String = listbox.ColumnWidths.Split(",")
  
  While widths.Count < listbox.ColumnCount
    widths.Add("*")
  Wend
  
  widths(column) = value
  
  listbox.ColumnWidths = String.FromArray(widths, ",")
End Sub

Now you can use it with any WebListBox:

MyListBox1.ColumnWidth(0) = "30%"
MyListBox1.ColumnWidth(1) = "*"
MyListBox1.ColumnWidth(2) = "125"

I hope that helps.

3 Likes

Thank you very much Ricardo
Will try it out.

BTW, this is the second time I am trying to convert from API1 to API2. I really wish that Xojo would have kept the much more generic names since now it is much much harder and a LOT more work to update older apps to the newer Xojo releases…

1 Like