如何判断用户使用的BindingSource修改的数据? [英] How to tell if user has modified data using bindingsource?

查看:539
本文介绍了如何判断用户使用的BindingSource修改的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView绑定到它绑定到一个列表℃的BindingSource的; T> 。用户点击某行去与文本框形式,等文本框的数据绑定像这样:

I have a DataGridView bound to a bindingsource which is bound to a List<T>. The user clicks a row that goes to a form with textboxes, etc. The textboxes are databound like so:

if (txtID.DataBindings.Count == 0)
    txtID.DataBindings.Add("Text", bindingSource, "Title");

我希望能够检测用户是否修改控件的任何数据,当他们点击关闭按钮,这样我就可以促使他们说:你有未保存的工作。你想保存?

I want to be able to detect if the user has modified any data in the controls when they click the close button, so I can prompt them to say "You have un-saved work. Do you want to Save?"

我如何检测这种绑定源?

How do I detect this on the binding source?

更新:我已经做了我能做的 bindingSource.EndEdit()其推动在列表中更改为我的项目。在我的项目,我就可以说,如果脏抛出一个消息框,但如果他们点击否来保存资料,CancelEdit不起作用。

UPDATE: I have worked out that I can do bindingSource.EndEdit() which pushes the changes to my item in the list. In my item, I can then say if Dirty throw a Messagebox but if they click "No" to saving the information, the CancelEdit does not work.

推荐答案

这是我更新的问题,我发现我已经来存储使用Memberwise.Clone在BeginEdit对象的当前版本,然后在CancelEdit我恢复了到当前。

From my updated question I found I had to store a current version of the object at BeginEdit using Memberwise.Clone and then in CancelEdit I restored that to the current.

这篇关于如何判断用户使用的BindingSource修改的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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