Click here to Skip to main content
15,896,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please some one tell me how to validate all text box, combo box and date time pickers at once in windows application

I have tried for single text box, but I don't know how to validate all controls in a single form.
My code to validate one text box control is

C#
private void txtcmpname_Validating(object sender, CancelEventArgs e)
{
	if (((TextBox)sender).Text == "")
	{
		MessageBox.Show("You must enter a ccomplaintname.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
		e.Cancel = true;
	}
}
But whenever I added another text box or combo box validation then that is not working properly and a blank record is inserted in the database.

Please provide me the solution
Posted
Updated 24-Sep-11 23:51pm
v3

1 solution

To really understand your question, I'd need to know how the code that updates the database is called ... automatically ? In response to some user action ?

Why can't you use a single class-scoped boolean variable, something like:

private bool IsAllControlsVerified = false;

which is set to 'false' initially, and then reset to 'false after each database update, and then have a function that tests for each control being validated, and, only if all of them are validated, sets this flag to 'true ?

The database update, of course, being allowed to proceed only if this flag if 'true.

Please expand your explanation of what you are trying to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900