Android Question [Solved]Delete table row based on value of 1st column

tcgoh

Active Member
Licensed User
Longtime User
Hi,

I have a table with empty cell in 1st column, how do i delete the row based on the 1st column,

For i = 0 To Table1.NumberOfRows -1
Dim row() As Object = Table1.GetValue(0,i)
Dim name As String = row(0)
If name = "" Then
Table1.RemoveRow(i)
Return
End If
Next

The above don't work. Any help thanks.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Is the string really empty? If so you could try:
B4X:
For i = 0 To Table1.NumberOfRows -1
    Dim row() As Object = Table1.GetValue(0,i)
    Dim name As String = row(0)
    If name.Length = 0 Then
        Table1.RemoveRow(i)
        Return
    End If
Next 

'Or if there could be spaces in it

For i = 0 To Table1.NumberOfRows -1
    Dim row() As Object = Table1.GetValue(0,i)
    Dim name As String = row(0)
    If name.Trim.Length = 0 Then
        Table1.RemoveRow(i)
        Return
    End If
Next

- Colin.
 
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
The line
Dim row() as object = table1.getvalue(i)
Don't match as one is object vs strings ??
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
I would do it like this, removing all rows with an empty value in the first column:
B4X:
For i = Table1.NumberOfRows -1 To 0
    Dim name As String = Table1.GetValue(0, i)
    If name = "" Then
        Table1.RemoveRow(i)
    End If
Next
Table1.GetValue(col, row) returns a String and not an array of objects !
Table1.GetValues(row) returns an array of Strings containing the values of all columns in the given row.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
I would do it like this, removing all rows with an empty value in the first column:
B4X:
For i = Table1.NumberOfRows -1 To 0
    Dim name As String = Table1.GetValue(0, i)
    If name = "" Then
        Table1.RemoveRow(i)
    End If
Next
Table1.GetValue(col, row) returns a String and not an array of objects !
Table1.GetValues(row) returns an array of Strings containing the values of all columns in the given row.
Thanks Klaus,
But this code doesn't work also. No error generated and the rows are not deleted.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, it should be:

B4X:
For i = Table1.NumberOfRows - 1 To 0 Step -1
    Dim name As String = Table1.GetValue(0, i)
    If name = "" Then
        Table1.RemoveRow(i)
    End If
Next
This code works, I tested it.
 
Last edited:
Upvote 0
Top