Windows Forms Input Validation with Validating Event and ErrorProvier Control

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Shalvin Shalvin is offline Offline May 15th, 2008, 5:29 am |
0
Checking whether value is entered into a control and preventing focus to go out if no value is entered.
Quick reply to this message  
C# Syntax
  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. }
0
bruceraymond bruceraymond is offline Offline | Jun 15th, 2008
C# has internal parsing routines that also work nicely.

Cheers,
Bruce


  1. double x;
  2. bool valid = double.TryParse( initialValue.Text, out x );
 
 

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC