开发者

VB.NET ComboBox Validating?

开发者 https://www.devze.com 2022-12-17 11:56 出处:网络
I have 开发者_Python百科a ComboBox bound to a table field and I want to validate the selection, since only certain selections are valid depending on context. When in the On Validating Event how can I

I have 开发者_Python百科a ComboBox bound to a table field and I want to validate the selection, since only certain selections are valid depending on context. 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. 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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号