Public Sub XTableDataUpdated(XTable As B4XTable, lstColumns As List, TitleIncluded As Boolean)
Dim cvsB4XTable As B4XCanvas
cvsB4XTable.Initialize(XTable.mBase)
Dim ShouldRefresh As Boolean
Dim CellLabel As B4XView
Dim CellText As String
Dim HeaderLabel As B4XView
Dim HeaderText As String
For Each column As B4XTableColumn In lstColumns
Dim MaxWidth As Int
If TitleIncluded Then
HeaderText = column.CellsLayouts.Get(0).As(B4XView).GetView(0).Text
HeaderLabel = column.CellsLayouts.Get(0).As(B4XView).GetView(0)
MaxWidth = cvsB4XTable.MeasureText(HeaderText, HeaderLabel.Font).Width + 10dip
End If
For i = 0 To XTable.VisibleRowIds.Size - 1
Dim RowId As Long = XTable.VisibleRowIds.Get(i)
If RowId > 0 Then
CellLabel = column.CellsLayouts.Get(i + 1).As(B4XView).GetView(0)
If column.ColumnType <> XTable.COLUMN_TYPE_DATE Then
CellText = XTable.GetRow(RowId).Get(column.Id)
Else
CellText = DateTime.Date(XTable.GetRow(RowId).Get(column.Id))
End If
MaxWidth = Max(MaxWidth, cvsB4XTable.MeasureText(CellText, CellLabel.Font).Width + 10dip)
End If
Next
If MaxWidth > column.ComputedWidth Or MaxWidth < column.ComputedWidth - 20dip Then
column.Width = MaxWidth
ShouldRefresh = True
End If
Next
If ShouldRefresh Then
XTable.Refresh
End If
End Sub