すべてINotifyPropertyChangedを実装するオブジェクトの階層があります。BindingListから派生したカスタムリストもあります。
INotifyPropertyChangedを含意するオブジェクトをリストに追加すると、どういうわけかPropertyChangedイベントが自動的にワイヤーアップ/ListChangedイベントに変換されることを理解しています。
ただし、リストをDataGridViewのデータソースとして設定した後、グリッドの値を変更しても、ListChangedイベントは発生しません...コードにステップインすると、PropertyChanged()イベントは発生しません。 nullであるためにトリガーされます。これは、想定されているように、BindingListのListChangedイベントに接続/変換されていないことを意味すると思います...
例えば:
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));
}
}
}
そして、これが私のカスタムリストクラスです...
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]));
}
}
}
何かアイデアや提案はありますか?
ありがとう!
ジョシュ