views:

885

answers:

3

In good old MFC, the DDX routines would have built in validation for form entries. For example it was possible to automatically check if the user entered a string in a text box meant for numeric input.

Is there any such mechanism in Winforms? Obviously one can add handlers for the 'onChange' etc kind of events and do the processing there, but I am asking if there is any built-in mechanism.

thanks

A: 

No, I don't believe so, but you can easily derive a custom textbox that applies the kind of validation you require based on a parameter or property you set on its instance. Then you'd have a built-in mechanism. ;-)

Cerebrus
+2  A: 

You could certainly implement your own ValidatingTextBox with a Regex property which is validated, essentially, whenever you decide you want it to be validated (keystrokes, Enter key, loses focus, ...)

At the simplest level there are Validated and Validating events on the plain TextBox that you can supply handlers to for individual instances.

JMD
As well, I would recommend a framework that works on top of those events, MS Enterprise Library - Validation Block
Lucas B
+2  A: 

There have been a couple of attempts to replicate the richer ASP.NET validators on Windows forms. Check out this one by Billy Hollis

Conrad