I have implemented validation rules on a textBox in my WinForm and it works well. However it checks the validation only when I tab out of the field. I would like it to check as soon as anything is entered in the box and everytime the content changes. Also I'd like it to check validation as soon as the WinForm opens.
I remember doing this fairly recently by setting some events and whatnot, but I can't seem to remember how.
How will your data be valid if it isn't finished? i.e. a user types a number and you try and validate it as a date?
If you're using databinding, go to the Properties of the textbox. Open (DataBindings) at the top, click on the (Advanced) property, three dots will appear (...) Click on those. The advanced data binding screen appears. For each property of the TextBox that is bound, in your case
Text
, you can set when the databinding, and thus the validation, should "kick in" using the comboboxData Source Update mode
. If you set it toOnPropertyChanged
, it will re-evaluate as you type (the default isOnValidation
which only updates as you tab).You should be checking on KeyPress or KeyDown events and not just your TextChanged event.
Here is a C# Example direct from the MSDN documentation:
When binding your textbox to a bindingSource go to Advanced and select validation type
"On Property Changed". This will propagate your data to your entity on each key press. Here is the screen shot
TextChanged event
in the future you can find all of the events on the MSDN library, here's the TextBox class reference:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox(VS.80).aspx