Winform Validation: Keypress vs TextChanged

May 1, 2006 at 8:56 pm Leave a comment

Suppose I want to run a validation routine when the text changed, one could have it call an validateField either by keypress (keydown, keyup, etc) or TextChanged.

private void validateField(){

if (HasPeriod(this._myfield)

{

     this._myFormErrorProvider.SetError(this._myfield, "Field must not have periods.");

}

else

{

this._myFormErrorProvider.SetError(this._myfield, "");}}

The routine uses a simple string search using val.IndexOf() to check if the string contains a period. What I have notice is that if I do this in a keypress event and I press a period key. The period won't be notice until I press another key. With a TextChanged event, the period is noticed right away.

Advertisements

Entry filed under: .Net, Winform.

Getting DVD Playback to work Ubuntu / Debian apt-get install build-essential issue

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

May 2006
M T W T F S S
« Apr   Jun »
1234567
891011121314
15161718192021
22232425262728
293031  

Most Recent Posts


%d bloggers like this: