2014-09-13 73 views
0

我使用2种方式与winforms文本框绑定。 我需要计算出用户是否已经改变了我的数据 帮忙寻找使用winforms数据绑定检测脏

the CurrentItemChanged Event

看来,如果一个属性改变了这一事件确实火,但它也激发如果目前已经改变。

有没有办法判断数据是否有变化?

a similar question is also asked here 但没有回答在我看来

奥利弗提到“如果列表中你的对象支持INotifyPropertyChanged的事件,并更换一个的BindingList列表,你可以订阅的BindingList的ListChanged事件得到通知关于用户所做的任何更改。“

我的应用程序符合这些条件,但我无法得到这个工作。 ListChangedType.ItemChanged属性看起来很有希望,但当我在不更改数据的情况下导航到下一条记录时,它会发生变化。

我找到了一个链接at Microsoft here,但肯定不能那么难!

回答

0

这似乎是工作

void bindingSource_BindingComplete(object sender, BindingCompleteEventArgs e) 
     { 
      if (e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate) 
      { 
       var person = (Person)bindingSource.Current; 

       if (person.State == State.Unchanged && (e.BindingCompleteState == BindingCompleteState.Success) 
       && e.Binding.Control.Focused) 
       { 
        person.State = State.Modified; // using Julie Lerman's repositories technique 
       } 
      } 
     }