AlfaizDev Well-Known Member Licensed User Longtime User Feb 22, 2025 #1 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 Project.zip Project.zip 15.6 KB · Views: 259
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
aeric Expert Licensed User Longtime User Feb 22, 2025 #2 AlfaizDev said: after deleting a row, one of the rows appears with a value of null Click to expand... Deleting a row doesn't actually remove the row from the list. AlfaizDev said: this issue appears if the table contains more than one page Click to expand... 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: Feb 22, 2025 Upvote 0
AlfaizDev said: after deleting a row, one of the rows appears with a value of null Click to expand... Deleting a row doesn't actually remove the row from the list. AlfaizDev said: this issue appears if the table contains more than one page Click to expand... 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
AlfaizDev Well-Known Member Licensed User Longtime User Feb 22, 2025 #3 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 Attachments Project2.zip Project2.zip 16.1 KB · Views: 261 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
aeric Expert Licensed User Longtime User Feb 22, 2025 #4 AlfaizDev said: 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 View attachment 161984 Click to expand... This worth a different question. Upvote 0
AlfaizDev said: 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 View attachment 161984 Click to expand... This worth a different question.
AlfaizDev Well-Known Member Licensed User Longtime User Feb 23, 2025 #5 aeric said: This worth a different question. Click to expand... 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
aeric said: This worth a different question. Click to expand... 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
aeric Expert Licensed User Longtime User Feb 23, 2025 #6 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: Feb 23, 2025 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
AlfaizDev Well-Known Member Licensed User Longtime User Feb 23, 2025 #7 aeric said: 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 Click to expand... 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
aeric said: 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 Click to expand... 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