开发者

Tabbing off control bypasses validation .NET

So, I have a User Control which is just a TextBox with special formatting rules (there are reasons why I'm not just using a MaskedTextBox...y'know...the sensible solution).

Anyhow, when the user inputs invalid data, they can't click off using the mouse because the TextBox_Validating event cancels like it should and the control can't lose focus until they enter acceptable input. However, if they try to tab off the control, the 'e.Cancel = True' statements are being hit (I know this by using breakpoints) but WinForms is still allowing them to tab off to the other controls, leaving invalid data in the TextBox.

What am I missin开发者_StackOverflowg to make tabbing act appropriately?


From version 2.0 of the .Net Framework you can use the Form.AutoValidate property to modify the validation behaviour. See the documentation for more information.

I just tested the tabbing issue, and it does not alow me to tab away when the validation fails (e.Cancel = true). When the validation succeeds (e.Cancel = false) everyting is alright.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜