views:

20

answers:

1

is there any collection that track changes made to the collection? say which object is deleted/modified/added?

The ObservableCollection just give notifications, it will not keep the removed in say a RemovedItems property. I have to keep them somewhere. actually why i am asking the question is if i bind a collection to a datagrid, it seems i have to do the change tracking myself, i wish there is a collection will do this so that i know how to update database using the collection.

The DataTable tracks changes, but it is not so easy to work with.

+2  A: 

Try ObservableCollection. From the reference text:

Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.

EDIT. You may also want to try solving your problem by using data sets (i.e. the DataSet class and related). They can do row versioning and keep track of row state changes (new, edited, deleted), so it may work for you. This is a good introduction to the topic: http://msdn.microsoft.com/en-us/library/ww3k31w0.aspx

CesarGon
It just give notifications, it will not keep the removed in say a RemovedItems property. I have to keep them somewhere. actually why i am asking the question is if i bind a collection to a datagrid, it seems i have to do the change tracking myself, i wish there is a collection will do this so that i know how to update database using the collection. Thanks.
Benny
@Benny: I suggest you update your question with this clarification for the benefit of everybody. In any case, the class I am proposing may serve you well: you only need to listen to the events and save the items being changed yourself. There is no collection in the provided libraries that does the tracking for you. Just in case you feel adventurous, I am adding an edit to my answer.
CesarGon
Thanks. Edited my question. +1 for you.
Benny
You're welcome.
CesarGon