问题描述
我有一个绑定源,它的数据源是一个数据表.
所有的 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 仍然不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!