如何检测绑定到实体的绑定源的变化?
我有一个绑定到实体的绑定源。
normBindingSource.DataSource =
dowacodbEntities.norms.OrderBy(o1 => o1.UsePurpose_id).ThenBy(o2 => o2.Quantity);
然后绑定源显示在数据网格视图中。如果我使用数据集,我可以调用 HasChanges() 方法来检查用户是否进行了更改。此外,我发现 context.ObjectStateManager.GetObjectStateEntries(...) 似乎是我正在寻找的,但我不知道如何使用它。
我的目的是当用户离开表单时,会有一个消息框显示:“有一些更改,您想在退出之前保存它吗?”
I have a bindingsource which is bound to entity.
normBindingSource.DataSource =
dowacodbEntities.norms.OrderBy(o1 => o1.UsePurpose_id).ThenBy(o2 => o2.Quantity);
Then a bindingsource is displayed in a datagridview. If I use dataset, I can call HasChanges() method to check if there are changes have been made by user. Moreover, I found context.ObjectStateManager.GetObjectStateEntries(...) seems to be what I am looking for but I don't know how to use it.
My purpose is when user leaves form, there will be a message box shows : "There are some changes, would you like to save it before exit ?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个。我也遇到过这种情况。
创建一个检查修改的类。
只需在需要时调用该函数即可,主要是在关闭时。然后如果返回true,则先停止关闭并询问是否要进行更改。如果您还需要什么,请告诉我。
Try this. I also encountered that.
create a class that checks for modifications.
just call that function anytime you need it, mostly on closing. Then if it returns true, stop closing first and ask if changes want to be made. Let me know if you need anything else.
这是迄今为止最好的方法:
This is the best method so far :