问题描述
我有一个绑定到绑定源的 DataGridView,该绑定源绑定到 List<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()
将更改推送到列表中的项目.在我的项目中,我可以说如果 Dirty 抛出一个消息框,但如果他们单击否"来保存信息,则 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 修改了数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!