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.
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 combobox Data Source Update mode
. If you set it to OnPropertyChanged
, it will re-evaluate as you type (the default is OnValidation
which only updates as you tab).
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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With