Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Ok so this question has most probably asked ad nauseum and I have searched for a solution for far too long now.

please can someone point me to an article or some code examples of how to do the following.

I have a WPF page with a datagrid (it has two manually created columns) on it. I have a ViewModel which gets my data from a table in my database and populates the datagrid (through an ObservableCollection).

all i want to do is to edit\add\delete items on the datagrid and submit the changes back to the database. my observable collection does edit\add\delete items, but how the heck do I get notified of these changes?

thanks in advance.
Posted

1 solution

If you want to get notified about the ObservableCollection changes, you can register to the CollectionChanged event of it.
 
Share this answer
 
Comments
PJ du Preez 11-Nov-11 5:07am    
please could you show me how I would go about to do this?

would it be something like: MyCollection.CollectionChanged += OnCollectionChangedMethod
?
Shmuel Zang 11-Nov-11 5:31am    
Yes. You have to create a method like the following: void OnCollectionChangedMethod(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // ... } and, register to the CollectionChanged event like the following: MyCollection.CollectionChanged += OnCollectionChangedMethod;
PJ du Preez 11-Nov-11 5:32am    
Cool, thanks.... I got that working.... but then realized, i dont actually need to go this route. but thanks a mil.. 5 stars!

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