WebListbox ColumnWidths problem Xojo 2019 r3.1

Hello Everyone,

Is there any official work around on how we handle weblistbox columnwidths with percentages or any example?

lbshops1.ColumnWidths=“10%,10%,25%,15%,15%,15%,10%”

Thank you in advance.

Percentages are your friend with WebListBoxes, but you can also use ‘*’ or point size numbers. What problem are you trying to work around?

Hey David,

Thank you for your reply.
You can see on my previous post that despite the fact that i have a sum of percentages 100% for my column widths, the column sizes are wrong.
You can see that columns are not aligned correctly below the headers. Look the 2 last columns of my image for example where the problem is more obvious.

That is what i am trying to work around.

This is an ongoing issue. I largely fixed it with a Method I posted on this forum that divided the columns up evenly according to the relative size of their content, as a Double. Others may have a better solution.

You could try writing a Javascript function to fix the column widths, but I’m pretty sure the only other fix for this is the inverse of what David said - use fixed pixel sizes.

<https://xojo.com/issue/44591>
44591 - Weblistbox column does not correctly align with header when column widths are not expressed using fixed number.

Thank you both for the answers. I will check what I can do.
David It would be great if you could give me the link to your method.

I hope Xojo finally fix this issue.

Thank you again.

I have revised it since last posted, so here is the new version:

[code]Protected Sub doSetListBoxColumnWidths(myListBox As Object, totalPercent As Integer = 100, minChars As Integer = 10, maxChars As Integer = 100)
Dim columnCharacters(-1) As Integer 'Used by Desktop/Web
Dim totalCharacterWidth As Integer 'Used by Desktop/Web 'width of all column maximums to get 100%
Dim widthsArray(-1) As String
Dim ListCount As Integer

#If TargetDesktop Then
Dim tempListBox As Listbox = Listbox(myListBox)

#ElseIf TargetWeb Then
Dim tempListBox As WebListBox = WebListBox(myListBox)

#Else 'console?
Return
#EndIf

#If TargetDesktop Or TargetWeb Then
Redim columnCharacters(tempListBox.ColumnCount) 'set as 1-based array

'set a minimum size of one character so %'s work and empty columns don't have zero width
For tempInt As Integer = 0 To tempListBox.ColumnCount - 1
  columnCharacters(tempInt + 1) = Len(tempListBox.Heading(tempInt))
Next

'populate the array with the longest number of characters for each column
#If TargetDesktop Then
  ListCount = tempListBox.ListCount
#ElseIf TargetWeb Then
  ListCount = tempListBox.RowCount
#EndIf
For tempInt As Integer = 0 To ListCount - 1
  For tempInt2 As Integer = 0 To tempListBox.ColumnCount - 1
    columnCharacters(tempInt2 + 1) = Max(columnCharacters(tempInt2 + 1), Len(tempListBox.Cell(tempInt, tempInt2)))
  Next
Next

'check the columns are within their limits and get the total max widths to determine the % for each column
totalCharacterWidth = 0
For tempInt As Integer = 1 To columnCharacters.Ubound
  If columnCharacters(tempInt) < minChars Then columnCharacters(tempInt) = minChars
  If columnCharacters(tempInt) > maxChars Then columnCharacters(tempInt) = maxChars
  totalCharacterWidth = totalCharacterWidth + columnCharacters(tempInt)
Next

'determine the percentage width for each column
For tempInt As Integer = 0 To tempListBox.ColumnCount - 1
  If tempInt = tempListBox.ColumnCount - 1 Then
    widthsArray.Append("*") 'let the last column has all that is left!
  Else
    widthsArray.Append(Format(columnCharacters(tempInt + 1)/totalCharacterWidth * totalPercent, "####0.00") + "%")
  End If
Next
tempListBox.ColumnWidths = Join(widthsArray, ",")

#EndIf

End Sub
[/code]

Thank you so much David.

Have a nice rest of your day.

[quote=475703:@Tim Parnell]Feedback Case #44591
44591 - Weblistbox column does not correctly align with header when column widths are not expressed using fixed number.[/quote]

4 YEARS since this bug was reported. That’s nuts. AND it’s Ranked 17th.

FWIW, we have tried to fix this several times and none of the solutions fixed all of the edge cases.

FWIW, the new WebListbox in Web 2.0 does not suffer from this flaw.

Hi Greg,

I have the same issue on Xojo 2019 r3.1 with percentages and column widths.
What do you mean the new WebLsitbox in Web 2.0?

Web 2.0 is a major upgrade to Xojo’s web app framework. See here.

[quote=475774:@Sebastian Kapellas]Hi Greg,

I have the same issue on Xojo 2019 r3.1 with percentages and column widths.
What do you mean the new WebLsitbox in Web 2.0?[/quote]
Web 2.0 isn’t just an update to API 2, all of the controls are brand new.