To delete a ROW from a TABLE we use the DeleteRows()
formula.
But there is not a similar formula for deleting an ITEM from a LIST and it is not obvious how to do this with other formulas.
If you know the position, N, of your item in the list you can use…
myList.SetControlValue( myList.Splice( N,1) )
The Splice()
formula takes 2 parameters;
- the start position in the list to operate on - we use N
- the number of items to delete at that position - we use 1
- additional parameters can be added; they are the items to be inserted - we ignore that here
But if you do not know the position of the ITEM you want to delete you can use…
myList.SetControlValue( myList.Filter( CurrentValue != ITEM ) )
The Filter()
applies the parameter (as a conditional expression) to each item in the list.
This will return a new list containing only elements that evaluated as TRUE.
The condition CurrentValue != ITEM
will evaluate as…
- TRUE for all elements that are not ITEM
- FALSE for any elements that are equal to ITEM
So the result is to return a list with all the original elements EXCEPT any that are equal to ITEM.
Note that a good precaution is to use the ListCombine()
formula.
I have seen a great many cases where the list is not flat, but contains “Lists within Lists”.
Adding the ListCombine()
will ensure that you get the expected behavior in all cases.
So the formula becomes…
myList.SetControlValue( ListCombine(myList) .Filter( CurrentValue != ITEM) )
respect
Max