With reference to the following snippet:
[B4X] B4XTable - Resize columns based on content
I wanted the column width adjustment to also include the header.
I would suggest to replace that snippet with the following Sub:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Obviously you should call it from the DataUpdated event of the B4XTable:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			[B4X] B4XTable - Resize columns based on content
I wanted the column width adjustment to also include the header.
I would suggest to replace that snippet with the following Sub:
			
				B4X:
			
		
		
		Public Sub XTableDataUpdated(XTable As B4XTable, 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 XTable.Columns
        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 SubObviously you should call it from the DataUpdated event of the B4XTable:
			
				B4X:
			
		
		
		Private Sub B4XTable1_DataUpdated
    XTableDataUpdated(B4XTable1, True)
End Sub
			
				Last edited: 
			
		
	
								
								
									
	
		
			
		
	
								
							
							 
				 
 
		 
 
		