将 UserDeletingRow 上的 dataTable 中的行标记为已删除

发布于 2024-08-30 13:47:43 字数 255 浏览 10 评论 0原文

我有一个通过 BindingSourceControl 绑定到 winforms dataGridView 的数据表。我希望能够处理 dataGridView 中的 UserDeletingRow 事件并将 dataTable 中的行标记为已删除。然后,我需要能够检索标记为从数据表中删除的行,以便在单击“保存”按钮时可以从数据库中删除它们。请注意,我不想在每次触发 UserDeletingRow 时从数据库中删除,只在我的数据集中将该行标记为已删除。

谁能指出如何做到这一点?

I have a datatable bound to a winforms dataGridView via a BindingSourceControl. I want to be able handle the UserDeletingRow event from the dataGridView and mark the row in my dataTable as deleted. I need to then be able to retrieve the rows marked as deleted from the datatable so that I can delete them from my database when a Save button is clicked. Please not I dont want to delete from the database on each firing of UserDeletingRow, only mark that row as deleted in my dataset.

Can anyone point out how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

你曾走过我的故事 2024-09-06 13:47:43

我发现这样做的最好方法是确保在编辑开始之前在数据表/数据集上调用 AcceptChanges() - 当数据绑定到网格时,我在表单加载时执行了此操作。现在,当用户通过网格删除记录然后点击“保存”时,我可以按行的 rowState 过滤 dataTable 中的行以获取已删除的记录。请注意,每次用户删除一行时,dataTable 的行集合上的 Count 属性都会减一,但该行仍在 dataTable 中,只是标记为删除。

The best I found to do this is be sure to call AcceptChanges() on the dataTable/dataset before editing starts - I did this on form load when the data was bound to the grid. Now when the user deletes records via the grid and then hits "save", I am able to filter the rows in the dataTable by the row's rowState to get the ones that have been deleted. Note that the Count property on the rows collection of dataTable drops by one each time the user deletes a row, but the row is still in the dataTable, its just marked for deletion.

征﹌骨岁月お 2024-09-06 13:47:43

捕获集合中“要删除”的 rowId,然后创建一些方法并传递集合来处理记录的删除

Capture the "to be deleted" rowId(s) in a collection then create some method and pass the collection to handle the deletion of the records

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