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

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

问题描述

我有一个文本框绑定到表单上的对象的属性(实际上是几个文本框)。这是一个对象的编辑器。当我正在编辑一些对象并修改一个文本框中的值时,我无法从文本框中退出(无论是通过标签还是单击另一个文本框)。然而,并不总是如此 - 当编辑其他对象(同一类型)它可以正常工作。

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.

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

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