Remove item from a List of Lists

Hello,

I’m trying to remove itens from a list of lists if they are equal to 1 condition.
The result is, does not deletes all the indexes, only index 1 and 3, and shows the error regarding the length. “Trying to select item 4 of a list of 3”
I’m doing the debug and all it’s ok. Length = 5, check all the index 1,2,3,4,5 and shows the result.
Please help me understand what is missing or what i’m doing wrong?
I tried to check alternative solutions here, but i only found for lists with 1 column.


Ty in advance.

The list collapses as you remove items, so items that were at slot 5 are now in slot 4, etc.

To avoid this complication, remove items starting at the highest position and ending at position 1, stepping by -1.

Hello,

i tried that before, and the error doesnt show, but doesnt remove any item.

TY

Hello Neusa

See my site, it explains, with pictures, what goes wrong:
https://www.professorcad.co.uk/appinventorsnippets#DelListViewItems

1 Like

Hello

Ok, i understand the problem, but in my case i can’t select an item, you are using “selection” or “last item selected” because i want to remove taking into account a condition, so how can i do that without the index, without the select list item. I have to create a variable for the index ?

TY

Here is how to do it in a small sample app …

Capture multi_remove.aia (2.9 KB) when btnPopulate Click when ListView1 AfterPicking

The removal by value is done in the remove procedure.

I copy the Elements of the ListView into a temporary list , work on the temporary list, then copy it back to the ListView. (I am being conservative here, as I have no assurance that working directly on the ListView.Elements list will affect the ListView or trigger a redisplay of the ListView.)

1 Like

Sir, Is there possible to remove some items from the mid of list? For example, let us assume that there are 50 items in a list, can we remove 21 to 30th items from list?

Yes.

Have you tried using removeListItem . Be careful, once you remove item 21, there are no longer 50 items in that List (there are 49 :slight_smile: ).

You can remove them one by one, but because AI2 lists are linked lists, the numbering of the items collapses past the removed item.

The solution to this problem is to loop downwards from 30 to 21 in your removals.

for i = 30 to 21 by -1
   remove item i from list L
end
1 Like

Ok sir Thank you

Thank you for your response.