Android Question Problem with null after deleting a row in b4xtable

AlfaizDev

Well-Known Member
Licensed User
Longtime User
Hello, I ran into an issue where after deleting a row in the table, an error appears in the total amount and the reason is that after deleting a row, one of the rows appears with a value of null and this issue appears if the table contains more than one page
Here is the attached file.

Attached is an example of b4j and b4a and the issue appears on both platforms
 

Attachments

after deleting a row, one of the rows appears with a value of null
Deleting a row doesn't actually remove the row from the list.

this issue appears if the table contains more than one page
It is same if you only have 1 page.

This is how I fix it.
Code: Copy
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XTable1 As B4XTable
    Private RowsDeleted As Int
End Sub
Code: Copy
Sub DeleteRow (tbl As B4XTable, RowId As Long)
    tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))
    tbl.ClearDataView 'Updates the rows count.
    RowsDeleted = RowsDeleted + 1
End Sub
Code: Copy
Private Sub CalculateTotalColumnB4XTable1(Column As String) As Double
    Try
        Dim Total As Double = 0
        For i = 1 To B4XTable1.Size + RowsDeleted
            Dim row As Map = B4XTable1.GetRow(i)
            Log($"${i} : ${row}"$ )
            If row.Size > 0 Then
                Dim value As Double = row.Get(Column)
                Total = Total + value
            End If
        Next
 
        Log("Total of column 0: " & Total)
        xui.MsgboxAsync(Total, "Total of column 0: ")
    Catch
        Log(LastException)
        xui.MsgboxAsync(LastException, "LastException")
    End Try
    Return Total
End Sub
B4X: Copy
1 : {Computer Name=Dell Inspiron, Price=600.0}
2 : {}
3 : {Computer Name=Lenovo ThinkPad, Price=800.0}
4 : {}
5 : {Computer Name=Asus ZenBook, Price=900.0}
Total of column 0: 2300
 
Last edited:
Upvote 0
Thank you very much
The total works, but the error is still there.
It's visible when you print.
One of the undeleted columns shows a null value
See the screenshot and you can try
Here is the example with the printing form

Screenshot_٢٠٢٥٠٢٢٢-١٤٢٤١٥.png
 

Attachments

Upvote 0
This worth a different question.​
is still the same issue.
It was left with a value of null in both cases
Now it's only left in print
Oddly enough, it's in the table
 
Upvote 0
It's same.
Loop the values.
If the map has zero items, don't include it.

Code: Copy
For i = 1 To Table.Size
    Dim row As Map = B4XTable1.GetRow(i)
    If row.Size > 0 Then
        For Each Column As B4XTableColumn In Table.Columns
            PrintString = PrintString & "<tr>"
            PrintString = PrintString & $"<td>${row.Get(Column.Title)}</td>${CRLF}"$
            PrintString = PrintString & "</tr>"
        Next
    End If
Next
 
Last edited:
Upvote 0
It's same.
Loop the values.
If the map has zero items, don't include it.

Code: Copy
For i = 1 To Table.Size
    Dim row As Map = B4XTable1.GetRow(i)
    If row.Size > 0 Then
        For Each Column As B4XTableColumn In Table.Columns
            PrintString = PrintString & "<tr>"
            PrintString = PrintString & $"<td>${row.Get(Column.Title)}</td>${CRLF}"$
            PrintString = PrintString & "</tr>"
        Next
    End If
Next
B4X: Copy
For i = 1 To B4XTable1.Size + RowsDeleted
    Dim row As Map = B4XTable1.GetRow(i)
    If row.Size > 0 Then
        For Each Column As B4XTableColumn In Table.Columns
            PrintString = PrintString & "<tr>"
            PrintString = PrintString & $"<td>${row.Get(Column.Title)}</td>${CRLF}"$
            PrintString = PrintString & "</tr>"
        Next
    End If

Thank you very much aeric
The solution was close
But I went too far
 
Upvote 0
Back
Top