简体   繁体   English

VB.NET ComboBox验证吗?

[英]VB.NET ComboBox Validating?

I have a ComboBox bound to a table field and I want to validate the selection, since only certain selections are valid depending on context. 我有一个ComboBox绑定到一个表字段,并且我想验证选择,因为根据上下文,只有某些选择才有效。 When in the On Validating Event how can I get the Value before or what it is in the table.field before selection changed? 在“验证事件中”时,如何在更改选择之前在表格或字段中获取值?

The WinForms ComboBox control doesn't provide the functionality of being able to intercept a value change and cancel it. WinForms ComboBox控件不提供能够拦截并取消值更改的功能。 You can use the Validating event (or, as you describe, subclass the ComboBox and override OnValidating ), but these only allow you to keep the focus on the control. 您可以使用Validating事件(或者,如您所描述的,将ComboBox子类化并覆盖OnValidating ),但是这些方法仅使您可以将焦点放在控件上。 You can't actually "cancel" a value change through the validating events. 您实际上无法通过验证事件“取消”值更改。

There are several third-party (DevExpress, for example) packages that provide ComboBoxes that allow you to inspect both the initial and the new values when the value changes and cancel the change if desired, but the ComboBox provided in System.Windows.Forms does not. 有多个第三方(例如,DevExpress)软件包提供ComboBoxes,使您可以在值更改时检查初始值和新值,并根据需要取消更改,但是System.Windows.Forms中提供的ComboBox确实可以不。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM