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

Delete range from RadObservableCollection used as ItemsSource

3 Answers 668 Views
GridView
This is a migrated thread and some comments may be shown as answers.
recotech
Top achievements
Rank 1
recotech asked on 26 Mar 2019, 02:06 PM

Hello,

i am upgrading an old project that uses .NET 3.5 and Telerik UI for WPF 2012.x to the latest .NET and Telerik UI versions. I have a GridView whose ItemsSource is bound to a RadObservableCollection provided by a MVVM viewmodel. As i rememder i used this collection because of the RemoveRange-method which had some performance benefits compared to the ObservableCollection.Remove-method (suspending the collectionchanged-events).

But now i have the problem, that, if a least one column is sorted, not the correct rows are removed. The rows removed are those, that are in the place of the rows i want to delete if the table were unsorted. Deleting from an unsorted GridView works fine. If i use the Remove-method in a loop instead of the RemoveRange deleting works as expected in sorted and unsorted GridViews.

Is it not longer recommended to use the RadObservableCollection as an ItemsSource for a GridView or is it a bug?

3 Answers, 1 is accepted

Sort by
0
recotech
Top achievements
Rank 1
answered on 26 Mar 2019, 04:47 PM

Is it not possible to edit a post?

I forget to mention, that the problem with the wrong removed rows only applies to the UI. In the RadObservableCollection the correct entries are deleted. Changing the order in the GridView will then show the correct items.

0
Accepted
Martin Ivanov
Telerik team
answered on 28 Mar 2019, 12:54 PM
Hello Sebastian,

You can resolve this and keep the performance by calling the suspend the notifications of the collection and remove the items one by one. Here is an example in code: 
radObservableCollection.SuspendNotifications();
foreach (var item in itemsToRemove)
{
    radObservableCollection.Remove(item);
}
radObservableCollection.ResumeNotifications();
Can you please try this approach and let me know how it goes?

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
recotech
Top achievements
Rank 1
answered on 28 Mar 2019, 01:26 PM

Hello Martin,

yes, this will work. i figured out the same solution myself just an hour ago and wandted to post the answer just a few minutes after yours :)

best regards

sebastian

Tags
GridView
Asked by
recotech
Top achievements
Rank 1
Answers by
recotech
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or