944,161 Members | Top Members by Rank

Ad:
  • C# Code Snippet
  • Views: 4871
  • C# RSS
0

Windows Forms Input Validation with Validating Event and ErrorProvier Control

by on May 15th, 2008
Checking whether value is entered into a control and preventing focus to go out if no value is entered.
C# Code Snippet (Toggle Plain Text)
  1. private void txtName_Validating(object sender, CancelEventArgs e)
  2. {
  3. if (txtName.Text == "")
  4. {
  5. errorProvider1.SetError(txtName, "Name cannot be blank");
  6. e.Cancel = true;
  7. }
  8. else
  9. errorProvider1.SetError(txtName, "");
  10. }
Comments on this Code Snippet
Jun 15th, 2008
0

Re: Windows Forms Input Validation with Validating Event and ErrorProvier Control

C# has internal parsing routines that also work nicely.

Cheers,
Bruce


C# Syntax (Toggle Plain Text)
  1. double x;
  2. bool valid = double.TryParse( initialValue.Text, out x );
Newbie Poster
bruceraymond is offline Offline
5 posts
since Oct 2007
Message:
Previous Thread in C# Forum Timeline: draw inside form
Next Thread in C# Forum Timeline: New to C# need help with code PLEASE!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC