Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private B4XTable1 As B4XTable
Private XSelections As B4XTableSelections
Private B4XComboBox1 As B4XComboBox
Private PfeilColumn As B4XTableColumn
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
'load the layout to Root
Root.LoadLayout("Table")
FillSV
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub FillSV
Private NumberofRows As Int = 100
Private TableRowHeight As Int = 50dip
B4XTable1.RowHeight = TableRowHeight
' --- Define the rowcolors ---
Private TableColor1 As Int = Colors.RGB(184,204,228)
Private TableColor2 As Int = Colors.RGB(220,230,241)
B4XTable1.AddColumn("Text1", B4XTable1.COLUMN_TYPE_NUMBERS).Width = 50dip
B4XTable1.AddColumn("Text2", B4XTable1.COLUMN_TYPE_TEXT)
PfeilColumn = B4XTable1.AddColumn("Pfeil", B4XTable1.COLUMN_TYPE_TEXT)
PfeilColumn.Width = 50dip
PfeilColumn.Searchable = False
PfeilColumn.Sortable = False
B4XTable1.AddColumn("Text3", B4XTable1.COLUMN_TYPE_TEXT)'.Width = 20dip
' --- Set the rowcolors ---
B4XTable1.EvenRowColor = TableColor1
B4XTable1.OddRowColor = TableColor2
Dim Data As List
Data.Initialize
' --- Create table content ---
For iRow = 0 To NumberofRows - 1
Data.Add(Array(iRow + 1, $"XYZ${iRow + 1}"$, "", $"${iRow + 1}XYZ"$))
Next
' --- Fill the table ---
B4XTable1.SetData(Data)
B4XTable1.MaximumRowsPerPage = 10
B4XTable1.BuildLayoutsCache(10)
' --- Skipp header and add an ImageView to each of the flags column cells ---
For i = 1 To PfeilColumn.CellsLayouts.Size - 1
Dim pnl As B4XView = PfeilColumn.CellsLayouts.Get(i)
Dim iv As ImageView
iv.Initialize("")
pnl.AddView(iv, 5dip, 5dip, PfeilColumn.Width - 10dip, B4XTable1.RowHeight - 10dip)
Next
' MODE_SINGLE_CELL_TEMP - this Is the built-in selection mode. Unlike the other selection modes it disappears automatically.
' MODE_SINGLE_CELL_PERMANENT - selection of a single cell.
' MODE_SINGLE_LINE_PERMANENT - selection of a single line.
' MODE_MULTIPLE_CELLS - selection of multiple cells.
' MODE_MULTIPLE_LINES - selection of multiple lines
XSelections.Initialize(B4XTable1)
XSelections.Mode = XSelections.MODE_SINGLE_CELL_PERMANENT
B4XComboBox1.SetItems(Array("SINGLE_CELL_TEMP", "SINGLE_CELL_PERMANENT", "SINGLE_LINE_PERMANENT", "MULTIPLE_CELLS", "MULTIPLE_LINES"))
B4XComboBox1.DelayBeforeChangeEvent = 0
'uncomment if you want selections to be removed automatically when the cell or line are not visible.
' XSelections.AutoRemoveInvisibleSelections = True
End Sub
Sub B4XTable1_DataUpdated
For i = 0 To B4XTable1.VisibleRowIds.Size - 1
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
Dim pnl As B4XView = PfeilColumn.CellsLayouts.Get(i + 1) '+1 because the first cell is the header
Dim iv As B4XView = pnl.GetView(1) 'ImageView will be the 2nd child of the panel. The built-in label is the first.
If RowId > 0 Then
' Dim row As Map = B4XTable1.GetRow(RowId)
iv.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "Pfeiloben.png", iv.Width, iv.Height, True))
iv.Tag = $"Pfeiloben${i + 1}"$
Else
'empty row
iv.SetBitmap(Null)
End If
Next
XSelections.Refresh
End Sub
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
Dim RowData As Map = B4XTable1.GetRow(RowId)
Dim cell As String = RowData.Get(ColumnId)
Log($"Id: ${ColumnId} RowId ${RowId} Cell: ${ cell}"$)
XSelections.CellClicked(ColumnId, RowId)
If ColumnId = "Pfeil" And cell = "" Then
Dim pnl As B4XView = PfeilColumn.CellsLayouts.Get(RowId)
Dim iv As B4XView = pnl.GetView(1)
Dim TagStr As String = iv.Tag
Log(TagStr)
Dim su As ApacheSU
If su.StartsWith(TagStr,"Pfeiloben") = True Then
Log($"Found ${TagStr}"$)
iv.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "Pfeilnieder.png", iv.Width, iv.Height, True))
iv.Tag = $"Pfeilnieder${RowId}"$
End If
If su.StartsWith(TagStr,"Pfeilnieder") = True Then
Log($"Found ${TagStr}"$)
iv.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "Pfeiloben.png", iv.Width, iv.Height, True))
iv.Tag = $"Pfeilnieder${RowId}"$
End If
Sleep(200)
B4XTable1.Refresh
End If
End Sub
' --- Change the Sort Direction Arrow Color Based on its Direction ---
Sub B4XTable1_HeaderClicked (ColumnId As String)
Dim up As Boolean = B4XTable1.lblSort.Text = Chr(0xF0DE)
B4XTable1.lblSort.Text = ""
Sleep(50)
If Not(up) Then
B4XTable1.lblSort.Text = "D"
B4XTable1.lblSort.textColor= xui.Color_Red
Else
B4XTable1.lblSort.Text = "U"
B4XTable1.lblSort.textColor= xui.Color_Green
End If
End Sub
Sub B4XComboBox1_SelectedIndexChanged (Index As Int)
Dim mode As Int = Index + 1 'implementation detail. You should use the constants instead
XSelections.Mode = mode
End Sub
Sub btnClear_Click
XSelections.Clear
End Sub
Sub btnLog_Click
If XSelections.Mode = XSelections.MODE_SINGLE_CELL_TEMP Then
Log("Temporary mode. No selection")
Return
End If
Dim LineMode As Boolean = XSelections.Mode = XSelections.MODE_MULTIPLE_LINES Or XSelections.Mode = XSelections.MODE_SINGLE_LINE_PERMANENT
If XSelections.IsSelected = False Then
Log("Nothing is selected")
Else
Log($"First selected row id: ${XSelections.FirstSelectedRowId}"$)
If LineMode = False Then Log($"First selected column: ${XSelections.FirstSelectedColumnId}"$)
Dim sb As StringBuilder
sb.Initialize
If LineMode Then
sb.Append("The following rows are selected:").Append(CRLF)
For Each rowid As Long In XSelections.SelectedLines.Keys
sb.Append(rowid).Append(CRLF)
Next
Else
sb.Append("The following cells are selected:").Append(CRLF)
For Each rowid As Long In XSelections.SelectedLines.Keys
Dim cols As List = XSelections.SelectedLines.Get(rowid)
For Each col As String In cols
sb.Append("(").Append(rowid).Append(", ").Append(col).Append(")").Append(CRLF)
Next
Next
End If
Log(sb.ToString)
xui.MsgboxAsync(sb.ToString, "Selection")
End If
End Sub