我有所有执行INotifyPropertyChanged对象的层次结构。我也有从派生的BindingList自定义列表。

我的理解的是,当我添加转化为ListChanged事件的对象impelements INotifyPropertyChanged的到列表中,以某种方式PropertyChanged事件是自动有线升/

然而,当我把我的列表,我的DataGridView,当我在网格改变一个值,该ListChanged事件不火......当我踏进代码的数据源,事实证明了的PropertyChanged()事件并未触发becaue为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]));
          }
     }
}

任何意见或建议?

谢谢!

约什

有帮助吗?

解决方案

我觉得问题是,你打电话this.Items.Add()代替this.Add()。该Items属性返回基地List<T>,其Add()方法不会有你想要的功能。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top