Android Code Snippet [B4X] B4XTable - Delete Row

Erel

Administrator
Staff member
Licensed User
Deletes a row from the table.

B4X:
Sub DeleteRow (tbl As B4XTable, RowId As Long)
   tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId))
   Dim page As Int = tbl.CurrentPage
   Dim FirstIndex As Int = tbl.FirstRowIndex
   tbl.ClearDataView 'Updates the rows count.
   If FirstIndex + 1 >= tbl.mCurrentCount Then
       page = page - 1
   End If
   tbl.CurrentPage = page
End Sub
Usage example:
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
       DeleteRow(B4XTable1, RowId)
   End If
End Sub
 
Last edited:

Jaliento

New Member
Deletes a row from the table.

B4X:
Sub DeleteRow (tbl As B4XTable, RowId As Long)
   tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId))
   Dim page As Int = tbl.CurrentPage
   Dim FirstIndex As Int = tbl.FirstRowIndex
   tbl.ClearDataView 'Updates the rows count.
   If FirstIndex + 1 >= tbl.mCurrentCount Then
       page = page - 1
   End If
   tbl.CurrentPage = page
End Sub
Usage example:
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
       DeleteRow(B4XTable1, RowId)
   End If
End Sub

I copied this but it says
undeclared variable 'xui' is used before it was assigned in any value
undeclared variable 'result' is used before it was assigned in any value
 
Top