如何判断用户是否使用 bindingsource 修改了数据?

How to tell if user has modified data using bindingsource?(如何判断用户是否使用 bindingsource 修改了数据?)
本文介绍了如何判断用户是否使用 bindingsource 修改了数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到绑定源的 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 修改了数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)