Edit: Don't use this code. Use B4XTableSelections class instead:
www.b4x.com
This example depends on B4XTable v1.02+ and B4XCollections.
It is quite simple to implement custom selection logic.
Step #1: The Selection Color property in the designer should be set to transparent. This will disable the default cell click animation.
Step #2: We maintain a B4XSet with the selected rows ids. This set is updated in the CellClicked event:
Step #3: Whenever the data is updated, we need to go over the visible rows and update their visual state:
A B4J example is attached.
[B4X] B4XTableSelections - extended selection modes for B4XTable
B4XTableSelections extends B4XTable and adds new selection modes: SINGLE_CELL_TEMP - this is the built-in selection mode. Unlike the other selection modes it disappears automatically. SINGLE_CELL_PERMANENT - selection of a single cell. SINGLE_LINE_PERMANENT - selection of a single line...
This example depends on B4XTable v1.02+ and B4XCollections.
It is quite simple to implement custom selection logic.
Step #1: The Selection Color property in the designer should be set to transparent. This will disable the default cell click animation.
Step #2: We maintain a B4XSet with the selected rows ids. This set is updated in the CellClicked event:
B4X:
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
Dim Selected As Boolean
If SelectedRows.Contains(RowId) Then
SelectedRows.Remove(RowId)
Selected = False
Else
SelectedRows.Add(RowId)
Selected = True
End If
Dim Index As Int = B4XTable1.VisibleRowIds.IndexOf(RowId) 'Find the index of the visible row
SetRowColor(Index, Selected) 'Set its color
End Sub
Step #3: Whenever the data is updated, we need to go over the visible rows and update their visual state:
B4X:
Sub B4XTable1_DataUpdated
For i = 0 To B4XTable1.VisibleRowIds.Size - 1
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
SetRowColor(i, SelectedRows.Contains(RowId))
Next
End Sub
A B4J example is attached.
Last edited: