B4J Question B4XTable with B4XTableSelections and text colors

hazaal

Member
Licensed User
Longtime User
Hi All,

I have been using successfully following code borrowed from the forum, to change the text color in certain cells if the date in date-column is not current date:
B4X:
Private Sub wtable_DataUpdated                                                           
    For i = 0 To wtable.VisibleRowIds.Size - 1
        Dim RowId As Long = wtable.VisibleRowIds.Get(i)
        If RowId > 0 Then
            Dim col As B4XTableColumn = wtable.GetColumn("Date")
            Dim Value As String = wtable.GetRow(RowId).Get(col.Id)
            If is_current_date(Value) = False Then
                SetCellFontColor(wtable, i, wtable.GetColumn("Started"), xui.Color_Red)
                SetCellFontColor(wtable, i, wtable.GetColumn("Nimi"), xui.Color_Red)
                Continue
            Else       
                SetCellFontColor(wtable, i, wtable.GetColumn("Started"), xui.Color_Black)
                SetCellFontColor(wtable, i, wtable.GetColumn("Nimi"), xui.Color_Black)
            End If'                   
        End If
        
        If i Mod 2 = 0 Then
            SetRowColor(wtable,i, wtable.EvenRowColor)
        Else
            SetRowColor(wtable,i, wtable.OddRowColor)
        End If       
    Next
End Sub

Sub SetCellFontColor (table As B4XTable, RowIndex As Int, Col As B4XTableColumn, Clr As Int)
    Dim pnl As B4XView = Col.CellsLayouts.Get(RowIndex + 1) '+1 because of the header
    pnl.GetView(0).TextColor = Clr
End Sub

It worked fine... until I added B4XTableSelections to get MODE_SINGLE_LINE_PERMANENT behavior

B4X:
WSelections.Initialize(wtable)
WSelections.Mode = WSelections.MODE_SINGLE_LINE_PERMANENT

Now when bx4table data is updated, I still get red text color where it is supposed to be, but in the moment I select a row, all text in the whole table changes to black. Same happen if selection mode is to set MODE_SINGLE_CELL_PERMANENT

1724959620592.png

like this, nothing else is done but clicked the table
1724959723383.png


In CellClicked-event has only selection handling

B4X:
Private Sub wtable_CellClicked (ColumnId As String, RowId As Long)
    WSelections.CellClicked(ColumnId, RowId)
End Sub

What am I doing wrong?

Thanks already!

Br,
-Harri
 

hazaal

Member
Licensed User
Longtime User
Sorry, the moment after pressing Post reply, I figured out B4XTableSelections-source is right there on different tab of IDE. Too long time away from B4X...

So, maybe not the most elegant way, but at this time of night, this will suit me. Edits for B4XTableSelections Refresh-sub highlighted:

B4X:
Public Sub Refresh
    For i = 0 To mTable.VisibleRowIds.Size - 1
        Dim clr As Int
        If i Mod 2 = 0 Then clr = mTable.EvenRowColor Else clr = mTable.OddRowColor
        Dim RowId As Long = mTable.VisibleRowIds.Get(i)
        Dim RowSelected As Boolean = SelectedLines.ContainsKey(RowId)
        If RowSelected And LineMode = False Then
            Dim SelectedCells As List = SelectedLines.Get(RowId)
        End If
        For Each col As B4XTableColumn In mTable.VisibleColumns
            Dim p As B4XView = col.CellsLayouts.Get(i + 1)
            Dim lbl As B4XView = p.GetView(col.LabelIndex)
            Dim mkey As String = col.Id & "." & i             
            If RowSelected And (LineMode Or SelectedCells.IndexOf(col.Id) > -1) Then
                map_of_cell_Colors.Put(mkey, lbl.TextColor)
                p.Color = SelectionColor
                lbl.TextColor = SelectedTextColor
                selected_row = i
            Else
                p.Color = clr
                If last_selected_row = i Then
                    Dim tclr As Int
                    Try
                        tclr = map_of_cell_Colors.Get(mkey)
                    Catch
                        tclr =  mTable.TextColor
                    End Try
                    lbl.TextColor = tclr
                End If             
            End If
        Next
    Next
    If AutoRemoveInvisibleSelections Then
        Dim RowsToRemove As List
        RowsToRemove.Initialize
        For Each RowId As Long In SelectedLines.Keys
            If mTable.VisibleRowIds.IndexOf(RowId) = -1 Then
                RowsToRemove.Add(RowId)
            End If
        Next
        For Each RowId As Long In RowsToRemove
            SelectedLines.Remove(RowId)
        Next
    End If 
    last_selected_row = selected_row
End Sub
 
Upvote 0
Top