viernes, 1 de julio de 2011

VB Helper: HowTo: Use validation events in VB .NET

VB Helper: HowTo: Use validation events in VB .NET: "Private Sub txtZip_Validating(ByVal sender As Object, ByVal _
e As System.ComponentModel.CancelEventArgs) Handles _
txtZip.Validating
' See if the text is 5 digits.
If Not (txtZip.Text Like '#####') Then
' The Zip code is invalid.
' Cancel the event moving off of the control.
e.Cancel = True

' Select the offending text.
txtZip.Select(0, txtZip.Text.Length)

' Give the ErrorProvider the error message to
' display.
ErrorProvider1.SetError(txtZip, 'Invalid ZIP code ' & _
'format')
End If
End Sub

' The ZIP code is valid. Clear the error.
Private Sub txtZip_Validated(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles txtZip.Validated
ErrorProvider1.SetError(txtZip, '')
End Sub"

No hay comentarios:

Publicar un comentario