数据绑定文本框:无法退出 [英] Data-bound TextBox: can't exit

查看:16
本文介绍了数据绑定文本框:无法退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框绑定到表单上的对象属性(实际上是几个文本框).这是一个对象的编辑器.当我在其中一个文本框中编辑一些对象并修改值时,我无法退出文本框(既不能通过选项卡也不能单击另一个文本框).然而,情况并非总是如此 - 当编辑其他对象(相同类型)时,它可以正常工作.

I've got a text box bound to an object's property (in fact several text boxes) on a form. This for is an editor for an object. When i'm editing some objects and modify values in the one of the text boxes i can't exit from the text box (neither by tab nor clicking on another text box). However that's not always the case - when editing other objects (of the same type) it works fine.

这是一个代码片段:

txtValue.DataBindings.Add("Text", _SourceObject, "PlannedValue", True, DataSourceUpdateMode.OnPropertyChanged, Nothing, "c")
txtEstPlacements.DataBindings.Add("Text", _SourceObject, "EstimatedPlacementCount")
txtReference.DataBindings.Add("Text", _SourceObject, "Reference")

有什么建议吗?

推荐答案

听起来像是数据验证问题.检查表单上的控件是否将其 CausesValidation 属性设置为 true 或 false.

Sounds like a data validation issue. Check if the controls on the form have their CausesValidation properties set to true or false.

还要检查表单上的 AutoValidate 属性.它可能设置为 EnablePreventFocusChange(这是默认设置).

Also check the AutoValidate property on the form. It is probably set to EnablePreventFocusChange (which is the default).

也可能是文本框中提供的值无法转换为它在源数据对象上绑定的属性的类型.我相信 Convert 类用于此目的(尽管我在这里可能错了).

It may also be the case that the value being supplied in the text box can not be converted to the type of the property it is bound to on the source data object. I believe the Convert class is used for this (though I may be wrong here).

您可能想查看 MSDN 上的这篇文章winforms 验证的一些细节.

You may want to check out this article on MSDN that covers winforms validation in some detail.

这篇关于数据绑定文本框:无法退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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