使用winforms数据绑定检测脏

我正在使用双向绑定winforms文本框。 如果用户更改了我的数据,我需要解决这个问题

CurrentItemChanged事件

如果某个属性发生了变化,这个事件似乎会触发,但是如果当前的变化,它也会触发。

有没有办法判断数据是否已经改变?

这里也提出了类似的问题,但我认为没有回答

Oliver提到“如果List中的对象支持INotifyPropertyChanged事件,并且您通过BindingList替换List,则可以订阅BindingList的ListChanged事件,以获知用户所做的任何更改。”

我的申请符合这些条件,但我不能让这个工作。 ListChangedType.ItemChanged属性看起来很有希望,但是当我导航到下一条记录而不更改数据时它会发生变化

我在这里找到了微软的链接,但肯定不会那么难!

这似乎有效

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 } } }