取消后绑定源空记录 [英] Bindingsource empty record after canceledit

查看:78
本文介绍了取消后绑定源空记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绑定控件和绑定源有问题.我正在使用vb 2008和.net 2.0.
我有一些文本框绑定到绑定源中的列.
后端是Access数据库.

我正在使用bindingnavigator添加新记录.
additem事件工作正常.
如果用户单击图标以取消编辑,则代码将执行
bindingsource.canceledit.这似乎工作正常.行数
在导航器上返回到addnew事件之前的正确数字 发生了.但是,bindingsource似乎在其中有一个空记录 它.
当绑定源导航时,它最终到达空记录 取决于addnew事件触发时的位置.

收到的错误是invalidcastexception.发生此错误是因为记录已重新定位
,并且每次发生此代码时,代码都会使用绑定控件中的值执行计算.
但是当它导航到空记录时,绑定控件中的值将为null.

除了canceledit之外,还有其他代码可以删除空记录吗?

解决方案

尝试对数据集进行RejectChanges

I have a problem with bound controls and a bindingsource. I'm using vb 2008 and .net 2.0.
I have a few text boxes bound to columns in the binding source.
The backend is a Access database.

I'm using a bindingnavigator to add a new record.
The additem event works fine.
If the user clicks an icon to cancel edit, the code executes
bindingsource.canceledit. This seems to work fine. The row count
on the navigator returns to the correct number before the addnew event occurred. However, the bindingsource seems to have an empty record in it.
As the bindingsource navigates, it eventually gets to the empty record depending on where it's position was when the addnew event fired.

The error received is an invalidcastexception. This error occurs because the record is repostioned
and each time this occurs the code performs calculations using values from the bound controls.
But when it navigates to the empty record, the values in the bound controls are null.

Is there other code besides canceledit to remove the empty record?

解决方案

try RejectChanges on Dataset


这篇关于取消后绑定源空记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆