Android Question Delete B4XTable row

RB Smissaert

Well-Known Member
Licensed User
Longtime User
This is a follow up from the post: B4XTable - all rows and no header
https://www.b4x.com/android/forum/threads/b4xtable-all-rows-and-no-header.103519/

Quoting Erel:
"I'm pretty sure that you can do it without modifying the B4XTable code."

I think you can but than it looks to me you it wouldn't be the most efficient way.
The minimum change needed to the class (to make it run most efficient) would be to make the variable CountAll public. Then you could do in the provided example:
https://www.b4x.com/android/forum/t...ortable-searchable-customizable-table.102322/

In Main:

B4X:
Sub Globals
 Private lRowID As Long '<<<< added
 'etc.
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)
'This is the SQLite ROWID of the underlying table, corresponding with the clicked row and we can use this to delete a row
lRowID = RowId '<<<< added
Activity.Title = cell
End Sub

Sub btnDeleteRow_Click
B4XTable1.sql1.ExecNonQuery2("delete from data where rowid = ?", Array As String(lRowID))
B4XTable1.CountAll = B4XTable1.CountAll - 1
B4XTable1.Refresh
End Sub


RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
There is no such goal. It doesn't matter if a task as this takes 1ms or 2ms. No user will ever see any difference.

I am sure you are right there.
What code do you suggest we use to delete a row without altering the class?

RBS
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Code to delete the clicked row:
B4X:
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
   Dim sf As Object = xui.Msgbox2Async("Delete row?", "Title", "Yes", "Cancel", "No", Null)
   Wait For (sf) Msgbox_Result (Result As Int)
   If Result = xui.DialogResponse_Positive Then
       B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId))
       Dim first As Int = B4XTable1.FirstRowIndex
       B4XTable1.ClearDataView
       B4XTable1.FirstRowIndex = first
   End If
End Sub
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Code to delete the clicked row:
B4X:
Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
   Dim sf As Object = xui.Msgbox2Async("Delete row?", "Title", "Yes", "Cancel", "No", Null)
   Wait For (sf) Msgbox_Result (Result As Int)
   If Result = xui.DialogResponse_Positive Then
       B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId))
       Dim first As Int = B4XTable1.FirstRowIndex
       B4XTable1.ClearDataView
       B4XTable1.FirstRowIndex = first
   End If
End Sub

Not sure that code is quite OK.
In the mentioned example, go to the last page and keep deleting the very last row.
You will see that the last page keeps showing one row with data. This row has moved over from the
previous page.

RBS
 
Upvote 0
Top