BindingSource 上的 EndEdit 更新 DataTable,但 rowstate 仍然不变

EndEdit on BindingSource updates DataTable, but rowstate still unchanged(BindingSource 上的 EndEdit 更新 DataTable,但 rowstate 仍然不变)
本文介绍了BindingSource 上的 EndEdit 更新 DataTable,但 rowstate 仍然不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定源,它的数据源是一个数据表.
所有的 winforms 控件都在 bindingsource 中添加了数据绑定

I have a bindingsource which has a datasource which is a datatable.
All the winforms controls has added databindings to the bindingsource

我在 GUI 中进行值更改(写入控件的 .text 属性)

I do a value change in the GUI (writes to the controls' .text property)

然后在保存时我执行以下操作

then on Save i do following

  bsSending.EndEdit();      

((DataRowView)this.bsSending.Current).Row) 现在包含新值,但 RowState 仍保持不变.这怎么可能?在 GUI 中进行值更改之前,我没有对 AcceptChanges() 进行任何调用

((DataRowView)this.bsSending.Current).Row) now contains the new values, but the RowState is still unchanged. How can this be possible? I haven't any calls to AcceptChanges() before I make the value changes in the GUI

推荐答案

更新:

不知道为什么,但似乎调用特定行的 EndEdit 可以解决问题.该行的父级是一个数据表,该表的数据集是 bsSending Datasource 的数据源.调用 bsSending.EndEdit() 只会更新值,但不会更新行状态.

Don't know why, but it seems that calling the specific row's EndEdit does the trick. The row's parent is a datatable and the table's dataset is the datasource of the bsSending Datasource. Calling bsSending.EndEdit() only updates the values but doesn't update the rowstate.

我在 .net 上浏览过类似问题,它们表明在绑定数据之前对数据集调用 AcceptChanges() 时,您可能会收到此错误(值已更新到数据集,但行状态保持不变).不过,我还没有看到任何问题的解决方案,所以我保留了我的解决方法

I have surfed the .net for similiar problems and they indicate that when calling AcceptChanges() on the dataset BEFORE binding data, then you may get this error (values updated to dataset but rowstate remains unchanged). I haven't seen any solutions to the problem, though, so I keep my workaround solution

这篇关于BindingSource 上的 EndEdit 更新 DataTable,但 rowstate 仍然不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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子句?)