Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd be interested to know how people go about solving this rather common problem.

In an MVVM type application, I have an ObservableCollection containing a set of things which I want displayed in the GUI. I've used ObservableCollection so that it can handle things being added/removed/replaced etc. so I don't have to do the collection change notification myself. To keep it simple, let's just use strings as the things in the collection.

To initially populate this collection, and to regularly update it I have a data access method which gives me a generic list of string. This is called at regular intervals.

So, to instantiate the ObservableCollection I can just do this:
List<string> itemsFromDb = GetListOfStringsFromDatabase();
MyObservableCollection = new ObservableCollection(itemsFromDb);

At regular poll intervals, I call GetListOfStringsFromDatabase() again, and now want to merge this into the existing records in the OC.

The OC is stateful, the List is not. I can compare the two, remove things from the OC not in the list, and insert things that are missing but I don't really feel I should need to do this.

A simple way to keep an ObservableCollection up to date by repeatedly providing a 'target' list - any thoughts?
Posted
Comments
Member 14062058 26-Nov-18 5:03am    
no with whom yo u bind datagrid itemsFromDb or MyObservableCollection

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900