Android Question [SOLVED]How to find and paint same values in a B4XTable?

Daniel44

Active Member
Licensed User
Hi everyone!

I have a Bxtable that is retreaving some values from a sqlite db. Here's how i made that

B4X:
MostrarAllSORTEO
    
    TBLALLSORTEO.Refresh
    
    TBLALLSORTEO.AddColumn("ID",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 1
      
    ColumnaCongelada = TBLALLSORTEO.AddColumn("FECHA",TBLALLSORTEO.COLUMN_TYPE_TEXT)
    ColumnaCongelada.Width = 280
    ColumnaCongelada.Sortable = False
    TBLALLSORTEO.NumberOfFrozenColumns = 1
    TBLALLSORTEO.AddColumn("DIA",TBLALLSORTEO.COLUMN_TYPE_TEXT)
    TBLALLSORTEO.AddColumn("N1",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 90
    TBLALLSORTEO.AddColumn("N2",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 90
    TBLALLSORTEO.AddColumn("N3",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 90
    TBLALLSORTEO.AddColumn("N4",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 90
    TBLALLSORTEO.AddColumn("N5",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 90
    TBLALLSORTEO.AddColumn("N6",TBLALLSORTEO.COLUMN_TYPE_TEXT).Width = 90
    
        
    Dim ListaSorteosSORTEO As List
    ListaSorteosSORTEO.Initialize
    Dim LC As List
    Dim SORSORTEO  As OPERACION
        
    LC = ops.ALLSORTEOS("")
    
    For i = 0 To LC.Size-1
        SORSORTEO = LC.Get(i)
        
        Dim Row(10) As Object
 
        Row(0) = SORSORTEO.rowid
        Row(1) = SORSORTEO.ALLSORTEONROSORTEO
        Row(2) = SORSORTEO.ALLSORTEOOFECHA
        Row(3) = SORSORTEO.ALLSORTEODIA
        Row(4) = SORSORTEO.ALLSORTEON1
        Row(5) = SORSORTEO.ALLSORTEON2
        Row(6) = SORSORTEO.ALLSORTEON3
        Row(7) = SORSORTEO.ALLSORTEON4
        Row(8) = SORSORTEO.ALLSORTEON5
        Row(9) = SORSORTEO.ALLSORTEON6
        
        
        ListaSorteosSORTEO.Add(Row)
    Next
    TBLALLSORTEO.SetData(ListaSorteosSORTEO)
End Sub

What I need is when i click any value on the table, every SAME values in this page of bxtable be colored. Like this:
SELECT SAME NUMBER.png

I hope you can help me. Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
java_VZfpimIcvH.gif


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XTable1.AddColumn("col 1", B4XTable1.COLUMN_TYPE_NUMBERS)
    B4XTable1.AddColumn("col 2", B4XTable1.COLUMN_TYPE_NUMBERS)
    B4XTable1.AddColumn("col 3", B4XTable1.COLUMN_TYPE_NUMBERS)
    Dim data As List
    data.Initialize
    For i = 1 To 88
        data.Add(Array(Rnd(1, 10), Rnd(1, 10), Rnd(1, 10)))
    Next
    B4XTable1.SetData(data)
End Sub

Private Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    Dim value As Object = B4XTable1.GetRow(RowId).Get(ColumnId)
    SetLabelsState(value)
End Sub

Private Sub SetLabelsState(Value As Object)
    For row = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim rowid As Long = B4XTable1.VisibleRowIds.Get(row)
        Dim rowdata As Map = B4XTable1.GetRow(rowid)
        For Each col As B4XTableColumn In B4XTable1.Columns
            Dim v As Object = rowdata.Get(col.Id) 'can be null
            Dim lbl As B4XView = col.CellsLayouts.Get(row + 1).As(B4XView).GetView(col.LabelIndex) 'note the +1 because of the header
            lbl.Font = IIf(Value = v, xui.CreateDefaultBoldFont(B4XTable1.LabelsFont.Size), B4XTable1.LabelsFont)
            lbl.TextColor = IIf(Value = v, xui.Color_Blue, B4XTable1.TextColor)
        Next
    Next
End Sub

Private Sub B4XTable1_DataUpdated
    SetLabelsState("")
End Sub
 
Upvote 1

Mahares

Expert
Licensed User
Longtime User
Private Sub SetLabelsState(Value As Object)
Based on the OP's screenshot, he likes to see a border around the cell value clicked. So, I changed your code slightly to reflect that. Do you agree with it:
B4X:
Private Sub SetLabelsState(Value As Object)
    For row = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim rowid As Long = B4XTable1.VisibleRowIds.Get(row)
        Dim rowdata As Map = B4XTable1.GetRow(rowid)
        For Each col As B4XTableColumn In B4XTable1.Columns
            Dim v As Object = rowdata.Get(col.Id) 'can be null
            Dim pnl As B4XView = col.CellsLayouts.Get(row + 1)
            If Value= v Then
                pnl.SetColorAndBorder(xui.Color_transparent, 7dip, xui.Color_Red, 5dip)
            Else
                If row Mod 2 = 0 Then
                    pnl.SetColorAndBorder(B4XTable1.EvenRowColor, 0dip, B4XTable1.EvenRowColor, 0dip)
                Else
                    pnl.SetColorAndBorder(B4XTable1.OddRowColor, 0dip, B4XTable1.OddRowColor, 0dip)
                End If
            End If
        Next
    Next
End Sub
1685362630666.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Nice!

Better to keep the background in all cases:
B4X:
Dim background As Int = IIF(row Mod 2 = 0, B4XTable1.EvenRowColor, B4XTable1.OddRowColor)
If Value = V Then
 pnl.SetColorAndBorder(background, 7dip, xui.Color_Red, 5dip)
Else
pnl.SetColorAndBorder(background, 0dip, xui.Color_transparent, 0dip)
End If
 
Upvote 0
Top