撤消自 BindingSource 上次 EndEdit 调用以来的所有更改
以下是场景(使用绑定到 DataSet 中的 DataTable 的 BindingSource):
- 用户创建一个新的地址簿 联系方式,填写第一个和最后一个 数据绑定控件中的名称。
- 他按下“应用”,其事件 处理程序调用 BindingSource.EndEdit()。
- 然后他意识到有一个 错误,并添加了电子邮件地址。
- 但当他按下“应用”时, 验证失败(无效的电子邮件 格式),因此不会调用 EndEdit()。
- 他决定不进行编辑,并且 按取消按钮,其 事件处理程序调用 BindingSource.CancelEdit()。
- 但是,与其恢复到 新的接触只是第一次和 姓氏和没有电子邮件, BindingSource 已被摆脱 整个记录的。
有没有办法只撤消自上次调用 EndEdit() 以来的操作? 我的印象是 CancelEdit() 应该如何工作。
Here's the scenario (which uses a BindingSource bound to a DataTable within a DataSet):
- A user creates a new address book
contact, fills in the First and Last
name in data-bound controls. - He presses Apply, whose event
handler calls
BindingSource.EndEdit(). - He then realizes there was a
mistake, and adds an email address. - But when he presses Apply,
validation fails (invalid email
format), so EndEdit() isn't called. - He decides not to make the edit, and
presses the Cancel button, whose
event handler calls
BindingSource.CancelEdit(). - But, rather than reverting to the
new contact with just a First and
Last name and no email, the
BindingSource has instead gotten rid
of the entire record.
Is there any way to only undo actions since the last time EndEdit() was called? I was under the impression that's how CancelEdit() was supposed to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为解释,DataTable 仅保存记录的 2 个状态:原始状态和当前状态。 您的请求需要多个州。
为了实现您想要的效果,您应该将更改刷新到数据库(例如 Adapter.Update(table))以响应成功的应用。 这会将您的“当前”提升为“原始”,而下一个“取消”可以回退到原始状态。
但这可能符合也可能不符合您的要求。
As an explanation, the DataTable only holds 2 states for a record, the Original and Current. Your request would require multiple states.
To achieve what you want you should flush the changes to the database (eg Adapter.Update(table)) in response to a successful Apply. That promotes your Current to Original and the next Cancel can fall back to that.
This may or may not match your requirements though.