Re: ObservableCollection - notification when item has changed (not the collection)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hello David,

you'll have to bind to the PropertyChanged event of each row.

You could derive a collection from ObservableCollection to automate this.

Kind regards,
Henning Krause

"David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:M%Y2k.2034$L_.966@xxxxxxxxxxxxxxxxxxxxxxx
Hello,

I have defined:

public class RawStat : INotifyPropertyChanged
{
...
}


public class RawStatCollection : ObservableCollection<RawStat>
{
...
}


void rawStats_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
MessageBox.Show("RawStats changed");
}

var rawStats = new RawStatCollection();
rawStats.CollectionChanged += rawStats_CollectionChanged;



rawStats_CollectionChanged() is properly called when I add something to the collection , e.g.

rawStats.Add (new RawStat);


But if the RawStat itself is changed, even though it implements INotifyPropertyChanged, I am not getting a notification for rawStats_CollectionChanged. I would argue that I should be, since changing an item in a collection is changing the contents of the collection itself.

But, putting aside theoretical debate, is there any easy way to get notified when the RawStat has changed, short of sinking the PropertyChanged event for every RawStat I add to the collection?

Thanks,
David


.