Click here to Skip to main content
15,040,212 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to validate multiple textbox in windows form application c# please send code
Posted
Updated 10-Jul-14 1:17am
v2
Comments
[no name] 10-Jul-14 7:33am
   
"Gimme code" is not a question or a problem. What is it that you have tried to solve your own problem? Where is the code that demonstrates your problem? What is the problem with your code?

see something like this
bool emptyFound = false;
            foreach (Control c in this.Controls)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    if ((c as TextBox).Text == "")
                    {
                        emptyFound = true;
                        error.SetError(c, "Valid input required");
                    }
                    else
                    {
                        error.SetError(c, "");
                    }
                }
            }
                return emptyFound;
   
C#
this.textBox1.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox2.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);
this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.textBox_Validating);

// And so on for the 20 boxes.
private void textBox_Validating(object sender, CancelEventArgs e)
{
    TextBox textbox = (TextBox)sender;

    // Do whatever yo need to do with textbox here.
}
   

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