VB.NET ComboBox Validating?
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.
精彩评论