Click here to Skip to main content
14,970,143 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a window form in .net framework.there are some textboxes and comboboxes. and checkboxes . i want to use validations in there controls . please send me some examples for help

What I have tried:

how to use validated and validating events
Updated 3-May-16 0:20am
BillWoodruff 3-May-16 6:25am
What works here is that you put your fingers on the keyboard and start studying some resources ... in this case those resources are very easy to find. Then, come back here with specific questions once you've started to work in code.

This forum is for answering specific questions not giving tutorials.

The MS documentation is the best place to start
User Input Validation in Windows Forms[^]
Control.Validating Event (System.Windows.Forms)[^]

and this blog explains how to use both events Validation in Windows Forms[^]

If you hit a specific problem then do come back with your code and we will try to help
Assuming the Control.CausesValidation Property (System.Windows.Forms)[^] is set to true:
The Validating event happens when the user tries to move away from a control, immediately after the Leave event, and allows you to cancel the attempt to leave if your validation fails by setting the Cancel property of the supplied CancelEventArgs. It you set Cancel to true, the focus will not move away from the control.
The Validated event happens immediately after the Validating event - provided it doesn't set the Cancel property - and allows you to work with the validated data.
private void tbSolution_Validating(object sender, System.ComponentModel.CancelEventArgs e)
    TextBox tb = sender as TextBox;
    if (tb != null)
        e.Cancel = !tb.Text.StartsWith("A");

private void tbSolution_Validated(object sender, EventArgs e)
    TextBox tb = sender as TextBox;
    if (tb != null)
        Console.WriteLine("{0} is OK!", tb.Text);

The text will only be printed provided it starts with the letter 'A'

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