Are you always deleting the same record, or have you tried different ones.
I'd do a trace just before removeItemAt(selectedItem.id
is it returning 0?
Your handling of the selectedItem seems strange (I'm assuming that parentDocument.contactListAC is the DG dataProvider.).
At the line :
you are using selectedItem as an integer index for ArrayCollection insertion. But then at the line :
you are using it as an object whose id is the ArrayCollection index.
So which one is it?
If I put an alert and show either of the lines:
The alert shows the same number, being the id of the item I want to remove. I have tried both and they do the same thing. Whats strange is when I press delete button the first item in the DG gets removed. This occurs after I filter the DG to say... Smith and try and delete my name the first Smith in the DG gets removed.
can you explain why are you doing this:
plus usage does not seem to be correct, second parameter to setItemAt should be index of the item not Item
assuming selectedItem is not a number..
Without it nothing happens.
Have you tried that?
Just did and nothing happens. I was thinking that as well. Thanks though
and you remembered to change it here also right?
Yes I did do like you show and a few others. How I have it from the beggining is the closest it just deletes the wrong record from the DG. But it deletes the correct record from the DB.
Thanks for the help, I realize I have about 5 large apps that do the same thing when trying to delete a record from an ArrayCollection.
Like others said, you should not be using object ot their ids as index to insert in or remove from the ArrayCollection, but the ArrayCollection index.
myDG.removeItemAt( myDg.getItemIndex( itemToRemove ) ); or myDG.setItemAt( itemToAdd , myDG.getSelectedIndex( myItemToReplace ) );
And from the look of your code, changing the indexes used in the ArrayCollection access will not change the item removed from the DB.