撤消自 BindingSource 上次 EndEdit 调用以来的所有更改

发布于 2024-07-29 10:54:38 字数 515 浏览 5 评论 0原文

以下是场景(使用绑定到 DataSet 中的 DataTable 的 BindingSource):

  1. 用户创建一个新的地址簿 联系方式,填写第一个和最后一个 数据绑定控件中的名称。
  2. 他按下“应用”,其事件 处理程序调用 BindingSource.EndEdit()。
  3. 然后他意识到有一个 错误,并添加了电子邮件地址。
  4. 但当他按下“应用”时, 验证失败(无效的电子邮件 格式),因此不会调用 EndEdit()。
  5. 他决定不进行编辑,并且 按取消按钮,其 事件处理程序调用 BindingSource.CancelEdit()。
  6. 但是,与其恢复到 新的接触只是第一次和 姓氏和没有电子邮件, BindingSource 已被摆脱 整个记录的。

有没有办法只撤消自上次调用 EndEdit() 以来的操作? 我的印象是 CancelEdit() 应该如何工作。

Here's the scenario (which uses a BindingSource bound to a DataTable within a DataSet):

  1. A user creates a new address book
    contact, fills in the First and Last
    name in data-bound controls.
  2. He presses Apply, whose event
    handler calls
    BindingSource.EndEdit().
  3. He then realizes there was a
    mistake, and adds an email address.
  4. But when he presses Apply,
    validation fails (invalid email
    format), so EndEdit() isn't called.
  5. He decides not to make the edit, and
    presses the Cancel button, whose
    event handler calls
    BindingSource.CancelEdit().
  6. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-08-05 10:54:38

作为解释,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文