Answered by:
deletion items from ListView

Question
-
Hello everyone!
I have very interesting problem! I have an ListView, that is populated with datasource. I want to delete some items from datasource.
There are a lot of examples, where items are deleted, after they are selected in ListView. I mean this:
listView.selection.getItems().done(function (items) {
items.forEach(function (currentItem) {
ds.beginEdits();
items.forEach(function (currentItem) {
ds.remove(currentItem.key);
});
ds.endEdits();
});
});It works, but I need to delete items, that are not selected. Please help me with it. It's important to solve this problem.
If I remove two or more items, I have 'noLongerMeaningfull' error.
Thanks!!- Edited by mykola semerenko Tuesday, August 21, 2012 4:50 PM
Tuesday, August 21, 2012 4:44 PM
Answers
-
Hi Mykola,
You have to pass the key to the data source. You are passing an index into the datasource.
For example... If you use this sample: http://code.msdn.microsoft.com/windowsapps/ListView-custom-data-4dcfb128 and you want to delete the first two items the keys are "0" and "1" for those two items.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, August 22, 2012 2:25 PM
- Marked as answer by mykola semerenko Wednesday, August 22, 2012 2:32 PM
Wednesday, August 22, 2012 2:25 PMModerator
All replies
-
Can you give an example of what problem you are having? Delete the item from the data source and you should be fine.
-Jeff
Jeff Sanders (MSFT)
Wednesday, August 22, 2012 1:12 PMModerator -
Thanks for a quick reply. Of course.
If I write this code, I will receive 'noLongerMeaningfull' error.
var ds = element.querySelector(".allSocialFeedList").winControl.itemDataSource;
ds.beginEdits();
ds.remove(0);
ds.remove(1);
ds.endEdits();I need to remove first and second items
- Edited by mykola semerenko Wednesday, August 22, 2012 2:19 PM
Wednesday, August 22, 2012 2:19 PM -
Hi Mykola,
You have to pass the key to the data source. You are passing an index into the datasource.
For example... If you use this sample: http://code.msdn.microsoft.com/windowsapps/ListView-custom-data-4dcfb128 and you want to delete the first two items the keys are "0" and "1" for those two items.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, August 22, 2012 2:25 PM
- Marked as answer by mykola semerenko Wednesday, August 22, 2012 2:32 PM
Wednesday, August 22, 2012 2:25 PMModerator -
Hi Jeff.
I am surprised that I was so blind. ))
It works perfectly. Many thanks to you.
Wednesday, August 22, 2012 2:32 PM