Hello,
This is a small utility to remove a row from ABMTable.
Keep in mind that :
For more complex table that consist not only String, I guest it could be achieve using temporary table instead of List.
Usage
Here is a sub to get No of Row & No of column, if source of table is from SQL Table
This is a small utility to remove a row from ABMTable.
Keep in mind that :
- table's rows only consist of String
- first column is assume as Table id
For more complex table that consist not only String, I guest it could be achieve using temporary table instead of List.
B4X:
Sub Process_Globals
Type CellInfo(Val As String,Thm As String)
End Sub
Sub CopyListtoTbl(TblRows As List,Tbl As ABMTable)
Private Id As String
Private TblCol As List
TblCol.Initialize
Private Cell As CellInfo
Cell.Initialize
Tbl.Clear
For x = 0 To TblRows.Size - 1
Private row As List
row.Initialize
Private rCellThemes As List
rCellThemes.Initialize
TblCol = TblRows.Get(x)
For y = 0 To TblCol.Size - 1
Cell = TblCol.Get(y)
If y = 0 Then Id = Cell.Val
row.Add(Cell.Val)
rCellThemes.Add(Cell.Thm)
Next
Tbl.AddRow(Id, row)
Tbl.SetRowThemes(rCellThemes)
Next
Tbl.Refresh
End Sub
Sub RemoveRow(Tbl As ABMTable,Id As String,NoOfRow As Int,NoOfCol As Int)
If Id = "" Then Return
Private TblRows As List
TblRows.Initialize
For x = 0 To NoOfRow - 1
If Tbl.GetString(x,0) <> Id Then
Private TblCol As List
TblCol.Initialize
For y = 0 To NoOfCol - 1
Private Cell As CellInfo
Cell.Initialize
Cell.Val = Tbl.GetString(x,y)
Cell.Thm = Tbl.GetCellTheme(x,y)
TblCol.Add(Cell)
Next
TblRows.Add(TblCol)
End If
Next
CopyListtoTbl(TblRows,Tbl)
End Sub
Usage
B4X:
RemoveRow(tbl1,tbl1.GetActiveRow ,4,3)
Here is a sub to get No of Row & No of column, if source of table is from SQL Table
B4X:
Sub TblAddRowFromSQL(SQ As SQL,Query As String, Tbl As ABMTable, TblRowTheme As String) As Int()
Try
Tbl.Clear
Private Values As ResultSet
Private Id As String
Private TblRows = 0 As Int
Private TblColumns As Int
Values = SQ.ExecQuery(Query)
TblColumns = Values.ColumnCount
Do While Values.NextRow
Private row As List
row.Initialize
Private rCellThemes As List
rCellThemes.Initialize
For i = 0 To TblColumns - 1
Id = Values.GetString2(0)
row.Add(Values.GetString2(i))
rCellThemes.Add(TblRowTheme)
Next
Tbl.AddRow(Id, row)
Tbl.SetRowThemes(rCellThemes)
TblRows = TblRows + 1
Loop
Values.Close
Return Array As Int(TblRows,TblColumns)
Catch
Log(LastException)
End Try
End Sub
Last edited: