2014-09-13 89 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 
       } 
      } 
     }