Reputation: 580
I'm trying to do some code that will do a "select-all" function. To achieve this, in the Code Behind I am trying to manually add all the list objects to the SelectedItems of the LongListMultiSelector.
The issue however is that when I do this, the list is augmented by two of the items, identical in their information. I have tried using SelectedItems.Add(...), SelectedItems.Insert(...) to no avail.
I have also tried to immediately remove one of the items from the list using SelectedItems.Remove(...), SelectedItems.RemoveAt(...) which will actually remove both entries, regardless of which I actually remove.
Lastly, I've tried changing one of the entries to NULL. This actually removes one of the entries in the list, but subsequently changes the remaining one to a null object itself. Am I doing this SelectAll feature in the right way? Is there a better alternative for what I want to achieve? Is it possible to continue with what I am doing and fix this duplication issue?
Upvotes: 2
Views: 1143
Reputation:
This worked for me, without adding duplicates:
private void OnSelectAllClick(object sender, EventArgs e)
{
LongListMultiSelectorName.SelectedItems.Clear();
foreach (var item in LongListMultiSelectorName.ItemsSource)
{
LongListMultiSelectorName.SelectedItems.Add(item);
}
}
Upvotes: 2
Reputation: 9223
The solutions is to "fake" an user selection as pointed out here : http://www.jonathanantoine.com/2013/04/18/wp-toolkit-adding-a-item-in-the-selecteditems-collection-of-a-longlistmultiselector-actually-adds-2/
foreach (var item in LongListMultiSelector.ItemsSource)
{
var container = LongListMultiSelector.ContainerFromItem(item)
as LongListMultiSelectorItem;
if (container != null) container.IsSelected = true;
}
Upvotes: 1