脏的检测使用的WinForms数据绑定 [英] Detecting dirty using winforms data binding

查看:187
本文介绍了脏的检测使用的WinForms数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用2的方式与WinForms的文本框的结合。
我需要计算出,如果用户改变了我的数据
纵观帮助

I am using 2 way binding with winforms text boxes. I need to work out if the user has changed my data Looking at the help for

的CurrentItemChanged事件

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

It seems that this event does fire if a property has changed, however it also fires if current has changed.

有没有办法来知道数据是否发生了变化?

Is there a way to tell whether the data has changed?

类似的问题也问这里
但在我看来没有回答

a similar question is also asked here but not answered in my opinion

奥利弗提到如果在列表中你的对象支持INotifyPropertyChanged的事件,并更换一个的BindingList可以订阅的BindingList的ListChanged事件来获得地了解用户所做的任何更改名单。

Oliver mentions "if your object within the List support the INotifyPropertyChanged event and you replace the List by a BindingList you can subscribe to the ListChanged event of the BindingList to get informed about any changes made by the user."

我的申请符合这些条件,但我不能得到这个工作。该ListChangedType.ItemChanged财产看上去充满希望,但是,当我浏览到下一个记录它改变不改变数据

My application meets these conditions but I cant get this working. The ListChangedType.ItemChanged property looked hopeful, but it changes when I navigate to the next record without changing the data

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

I found a link at Microsoft here but surely it cant be that hard!

推荐答案

这似乎是工作。

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

这篇关于脏的检测使用的WinForms数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆