Dim ShouldRefresh As Boolean
'NameColumn and NumberColumn are global B4XTableColumns that we want to measure
For Each Column As B4XTableColumn In NameColumn
Dim MaxWidth As Int
For Each id As Long In tblMain.VisibleRowIds
If id = 0 Then
Dim pnl As B4XView = Column.CellsLayouts.Get(0)
Dim lbl As B4XView = pnl.GetView(0)
MaxWidth = Max(MaxWidth, cvs.MeasureText(lbl.Text, lbl.Font).Width + 10dip)
Else
Dim Text As String = tblMain.sql1.ExecQuerySingleResult2($"SELECT ${Column.SQLID} FROM data WHERE rowid = ?"$, _
Array(id))
End If
MaxWidth = Max(MaxWidth, cvs.MeasureText(Text, tblMain.LabelsFont).Width + 10dip)
Next
If MaxWidth > Column.ComputedWidth Or MaxWidth < Column.ComputedWidth - 20dip Then
Column.Width = MaxWidth
ShouldRefresh = True
End If
Next
If ShouldRefresh Then
tblMain.Refresh
End If