This content has been marked as final. Show 3 replies
Tried a diferent approach, I would still expect the Method 1 or 2 to work properly especially method 2. This seems to work consistently every time
List<Integer> indices = tblViewDSResults.getSelectionModel().getSelectedIndices();
ObservableList<Map> items = tblViewDSResults.getItems();
for (int i = indices.size() - 1; i >= 0; i--)
The problem with your first approach is that you're getting a reference to the list of selected items. When you remove an item, that list will change. So as you progress through the loop (either explicitly in method 1 or implicitly in method 2), the item(s) you try to delete each time change.
You can fix it with
and then either method will work.
List<Map> items = new ArrayList<Map>(tblViewDSResults.getSelectionModel().getSelectedItems());
This is probably actually safer than using the list of selected indices, which has the potential to suffer from the same problem. That it works is only a result of the implementation of the selection model.
Edited by: James_D on Jan 23, 2013 7:26 AM (Fixed horrible grammatical error)
Thanks, worked great.