DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Code Snippet: Windows Forms Input Validation with Validating Event and ErrorProvier Control (http://www.daniweb.com/forums/thread217071.html)

Shalvin May 15th, 2008 5:29 am
Windows Forms Input Validation with Validating Event and ErrorProvier Control
 
Checking whether value is entered into a control and preventing focus to go out if no value is entered.

  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. }
bruceraymond Jun 15th, 2008 9:32 pm
C# has internal parsing routines that also work nicely.

Cheers,
Bruce


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


All times are GMT -4. The time now is 3:18 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC