|
|
Data Field Constraints For Forms
The code to place constraints (aka, text validation)
on your fields is significantly more difficult
than I thought it would be, so I've provided some sample code for a basic example.
Form2.cs sample code
Look at the event handlers I've created
and the extra functions I've added,
to see how you can modify them to meet your own needs.
Make sure you add the 'validated' and the 'validating' functions.
Then go to the properties of the field that you want to validate.
Select the events list (the lightening bolt at the top of the
properties box).
Change three of the fields to look like the fields I have in the screen print.
If you need to validate against entries in a table
(like to check for constraints before your program crashes with invalid data)
then consider this text inside your 'Validating' function:
System.Data.DataRow[] myArray = this.classdbDataSet.student.Select("sid = " + sidTextBox.Text.ToString());
if (myArray.Length == 0)
{
e.Cancel = true;
string errorMsg = "That SID not found in database.";
this.errorProvider1.SetError(sidTextBox, errorMsg);
}
The actual solution files to the 'email validation' example start here
if you want to load the program into your Visual C#.
That's it! Email me if you have any questions.
|
|
|