This is a migrated thread and some comments may be shown as answers.

Removing many items at once

3 Answers 40 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kristian
Top achievements
Rank 1
Kristian asked on 04 Mar 2014, 08:20 PM
In my app I have an ObservableCollection with 1000 items, and sometimes the user needs to remove 100 items at once.
The problem I have is that removing items one by one by calling the RemoveAt method takes too long to complete and the UI thread blocks for 3-5 seconds.
Is there a way to stop updating the view, and then after removing the items enable it again and redraw the list?

3 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 07 Mar 2014, 08:35 AM
Hello Kristian,

Can you try setting the ItemsSource to null, remove the items from your source, and again bind it to the listbox?

Regards,
Deyan
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

0
Kristian
Top achievements
Rank 1
answered on 07 Mar 2014, 08:42 AM
But this resets the vertical offset of the scrollviewer, and I need the ListBox to not change vertical offset if possible.
0
Deyan
Telerik team
answered on 07 Mar 2014, 08:47 AM
Hi Kristian,

Thanks for writing back.

You can also try calling BeginUpdate and EndUpdate before and after the update occurs. Anyway, I am afraid that considering the fact that the ObservableCollection does not expose a RemoveRange method and we therefore could not track which items have been removed, you will have to use some kind of trickery to achieve better performance.

Regards,
Deyan
Telerik

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Tags
DataBoundListBox
Asked by
Kristian
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Kristian
Top achievements
Rank 1
Share this question
or