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

itemssource is updated in a different thread, how to update GridView, with losing filter or sorting?

7 Answers 387 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erdem
Top achievements
Rank 1
Erdem asked on 09 May 2014, 09:00 PM

Hi,

I've been struggling a bit with the radgridview since the Itemssource can be updated somewhere else, but the thing is, it's the full collection that gets updated, and when this happens, the entire sorting/filter is lost.

I assume I have to make sure that only one specific item in the collection gets modified, but not quite sure what the best approach is here, since the collection is filled with Telerik DataAccess entities and if I'm not wrong there is not Inotifyproperty on the entities.

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 May 2014, 07:11 AM
Hello,

Do you specifically set the ItemsSource to null before assigning the new one?
Generally in order to preserve the sorting an filtering you should just Add/Remove items from the collection. This will raise a collection changed notification, RadGridView will refresh its data and all the defined descriptors will be reevaluated.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Erdem
Top achievements
Rank 1
answered on 12 May 2014, 01:34 PM


The thing is, that I need to use an extra workerThread in my application and I see that it's advised to use multiple DBContexts whenever using multiple threads....

Well, I've tried a few ways of doing this:

1. Create a collection in the code behind from OpenAccess => refill the collection when something changes in the database. => I lose sorting. (because it's a new list) => But how can I just modify those specific items in collection when another DBContext has changed the database.

3. use mvvm => same problem => the observablecollection needs to be loaded again because the entities in OpenAccess are no longer up to date. Because in another thread a new DBContext is created and database items are modified so my GridView is not aware....

Also I cant modify my observablecollection manually because it's created from OpenAccess and the data is no longer up to date and manuall change will result in a concurrency problem.

How can I update only 1 line/record/entity in my grid. Or update everything and re-apply sorting/filtering.


0
Erdem
Top achievements
Rank 1
answered on 12 May 2014, 01:58 PM

Maybe I should use the ObservableCollection as a central point in the application and whenever the worker thread creates items, I'll add those Items to the ObservableCollection.

When I want to modify. I create a new object and assign an Object from the ObservableCollection to it and then save changes when modified.

Multithreading should not be working on the same Object/entity at the same time. Is this a workable solution?
0
Dimitrina
Telerik team
answered on 13 May 2014, 10:13 AM
Hello,

Removing/Adding an item from an ObservableCollection will raise a CollectionChanged notification and this will ensure the item displayed into View is also updated. You can even remove and add the same instance after modifying it and not creating a new one.
In case you have a reference to RadGridView, you can also check the
Edit an item outside RadGridView article.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Heiko
Top achievements
Rank 1
answered on 05 Feb 2016, 03:57 PM

Hi!

Although this is somewhat old I got exactly the same problem: fill the ItemsSource of RadGridView -> Grouping and Sorting works. Refresh the ItemsSource again -> Grouping and Sorting is gone. What should I do?

Regards
Heiko

0
Dilyan Traykov
Telerik team
answered on 10 Feb 2016, 12:39 PM
Hello Heiko,

This behavior is expected, as when the ItemsSource of a RadGridView is changed, there is no guarantee that the columns and descriptors defined will be applicable to the type of the new data items. That is why, rather than risking exceptions in the LINQ runtime, they are cleared. You can have a look at a couple of similar threads discussed here and here.

One solution I can offer is to save the group/sort descriptors somewhere before resetting the data and add them to the GroupDescriptors/SortDescriptors collection after the data has come.

Regards,
Dilyan Traykov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Heiko
Top achievements
Rank 1
answered on 10 Feb 2016, 05:20 PM

Hello Dilyan,

thanks for the reply which which clarifies why this happens. Since I do grouping and sorting in XAML I have to find another way of doing it, but this is OK.

Suggestion for Telerik: add a property "Keep Grouping/Sorting" to GridView and rebuild the GroupDescriptors/SortDescriptors after the ItemsSource is changed. If it throws an exception and the property is true, simply give the developer the blame. :-)

Regards
Heiko

Tags
GridView
Asked by
Erdem
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Erdem
Top achievements
Rank 1
Heiko
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or