Android Question Remove rows in table class

h725

Active Member
Licensed User
Longtime User
Hello Community,

I have a question concerning the following topic:
I have a list, which holds ids. I am using the table module V1.43.
The table module offers the method 'removerow'. I would like to
remove the row which has the id of the list in the first column.



Code: Copy
dim row as integer = 0

dim removelist as list
removelist.initialize
removelist.add(1)
removelist.add(2)

For j = row To table.Size -1
    Dim o() As String
    o = table.GetValues(j)
       For i = 0 To removelist.Size -1
         Dim p() As String
         p = removelist.Get(i)
           If o(0) = p(0) Then
             table.RemoveRow(j)
           End If
       Next
Next

The problem is that the the size of the table (the number of rows)
reduces during the loop. So I get an exception. Any idea how to solve the
problem?

Kind regards
h725
 
Iterate through the list BACKWARDS if you want to remove items
 
Upvote 0
Somehow i do not get the progress.
Probably you help me with a small snippet.

Perhaps you can also show if there is a better way to
loop through the table and remove the rows which
have the id from the list in field(0) / column(0).

Thank you very much in advance.
 
Upvote 0
The solution is to go backwards. I do not have a table view to play with to write some code for you.
I do not have the problem.

A list (table) with 10 row have the indexes 0,1,2,3,4,5,6,7,8 and 9
If you iterate through the list
0,1,2,3,4 and then you remove 4 the list will shrink. BUT the iteration will still run till the specified endindex (9) but the list does not contain such items.

If you to from 9 to 0 step -1

9,8,7,6,5,4 (you now remove 4),3,2,1,0
 
Upvote 0
Try this:
Code: Copy
For j = table.Size -1 To row Step -1
    Dim o() As String
    o = table.GetValues(j)
    For i = 0 To removelist.Size -1
         Dim p() As String
         p = removelist.Get(i)
         If o(0) = p(0) Then
             table.RemoveRow(j)
         End If
    Next
Next
 
Upvote 0
I use another approach.
In paralel of the Table I use a List, lstIDs in the example below, where I save the IDs.
Then in your example:
Code: Copy
For i = 0 To removelist.Size -1
     Dim id, index As Int
     id = removelist.Get(i)
     index = lstIDs.IndexOf(id)
     table.RemoveRow(j)
     lstIDs.RemoveAt(i)
Next
 
Upvote 0
Thank you very much.
The backwards iteration was the solution.

Fast and high quality help. Excellent.
 
Upvote 0
Back
Top