Hello all,
I have a hierarchy of objects that all implement INotifyPropertyChanged. I also have a custom list that derives from BindingList.
It is my understanding that when I add an object that impelements INotifyPropertyChanged to the list, that somehow the PropertyChanged event is automagically wired-up / converted to the ListChanged event.
However, after I set my list as the datasource of my DataGridView, when I change a value in the grid, the ListChanged event does not fire... When I step into the code, it turns out that the PropertyChanged() event is not triggering becaue it is null, which I assume to mean that it is not getting wired-up / converted to the BindingList's ListChanged event, like its supposed to...
For example:
public class Foo : INotifyPropertyChanged
{
//Properties...
private string _bar = string.Empty;
public string Bar
{
get { return this._bar; }
set
{
if (this._bar != value)
{
this._bar = value;
this.NotifyPropertyChanged("Bar");
}
}
}
//Constructor(s)...
public Foo(object seed)
{
this._bar = (string)object;
}
//PropertyChanged event handling...
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
And here is my custom list class...
public class FooBarList : BindingList<Foo>
{
public FooBarList(object[] seed)
{
for (int i = 0; i < seed.Length; i++)
{
this.Items.Add(new Foo(this._seed[i]));
}
}
}
Any ideas or suggestions?
Thanks!
Josh