Hi All, I am writing a simple win form which contains a button, when user click the button i want to validate all the other textbox and see if there is anything goes wrong may i know how can i trigger the validating event for all text box? thx and regard,s Norton Norton, It sounds for me as a horse behind the car.thx and regard,s Norton Norton, I got the following tip from "Windows Forms Programming in C#" by Chris Sells, from Addison Wesley. How can something be wrong in a textbox when you use correct the validating event.Within your "Accept" button click handler (the "save" button) process each control that Causes Validation to ensure that they are all valid... (Assuming you are not placing conflicting date in there by the program) It will be executed as that control looses the focus. Cor Phill, Now I understood you, in fact do you want to check if they are not empty? Hope this helps Jay "norton" Hi All, I am writing a simple win form which contains a button, when user click the button i want to validate all the other textbox and see if there is anything goes wrong may i know how can i trigger the validating event for all text box?LISTING 5.4 USING THE VALIDATE EVENT PROCEDURE Private Sub txt Age_Validate(Cancel As Boolean) If Not Is Numeric(txt Age. Run(form1) End Sub End Class Public Class Form1 Inherits System. Protected Overloads Overrides Sub Dispose(By Val disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components. Dispose(disposing) End Sub Friend With Events Text Box1 As System.
To use the new Validate event, set the Causes Validation property to True for each field that could receive focus, which luckily is the default value for that property. Label 'Required by the Windows Form Designer Private components As System. Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. Resume Layout(False) End Sub #End Region Private Sub Text Box1_Text Changed(By Val sender As System. However, for code readability, it would make sense to place all validation code in the Validating event.So, which is the better option, in terms of both efficiency and industry-standards?Alternatively, you can set the Cancel parameter to False (the default) if you want to allow the end-user to continue entering data without immediately correcting the problem.You may want to use the Validate event without using the Cancel parameter.If you want to have a field on the form that the user can select without going through any validation, you can set the Causes Validation property to False for that field.For example, if you have a Help or Cancel button, you want to allow the user to select the button without having the current field validated. The above code will cause the Validating event for each of your controls to be raised, ensuring that all the controls get validated, before the dialog is closed or the data is saved... None Exit For End If End If Next Note this version does not validate controls nested within other container controls, such as Group Boxes, I would include the above in a recursive subroutine.