EndEdit on BindingSource updates DataTable, but rowstate still unchanged(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 仍然不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:BindingSource 上的 EndEdit 更新 DataTable,但 rowstate 仍然不变
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
