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.
MULTIPLE_CELLS - selection of multiple cells.
MULTIPLE_LINES - selection of multiple lines
Initialize B4XTableSelections and set the mode:
XSelections.Initialize(B4XTable1) XSelections.Mode = XSelections.MODE_SINGLE_CELL_TEMP
Implement these two events like this:
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long) XSelections.CellClicked(ColumnId, RowId) End Sub Sub B4XTable1_DataUpdated XSelections.Refresh End Sub
The example shows how to get the selected lines or cells.
In lines mode:
For Each rowid As Long In XSelections.SelectedLines.Keys Next
For Each rowid As Long In XSelections.SelectedLines.Keys Dim cols As List = XSelections.SelectedLines.Get(rowid) For Each col As String In cols 'cell is defined by (rowid, col) Next Next
You can also make selections programmatically by modifying SelectedLines collection and calling Refresh.
The class is included in the attached B4J example.
V1.04 - Fixes an issue with hidden columns.
V1.03 - New SelectedTextColor field.
V1.02 - Bug fix. New IsSelected property.
New FirstSelectedRowId and FirstSelectedColumnId methods. Especially useful in the single mode selections.
Depends on B4XCollections.
V1.01 - New AutoRemoveInvisibleSelections field. When True selections are removed automatically when the selected lines or cells are not visible.