How do I dynamically validate text using the TextChanged event in the EditControl?
(Views :1552)

This can be easily accomplished using the TextChanged event and a timer.

The validation routine is invoked in response to a brief pause in typing by the user.

Refer to the code snippets and the sample attached to know more about it.

C#
private void editControl1_TextChanged(object sender, System.EventArgs e)
{
// Do not start the timer as long as characters are being typed.
if (this.timer1.Enabled == true)
this.timer1.Stop();
this.timer1.Start();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.ValidateText();
this.timer1.Stop();
}
private void ValidateText()
{
// Perform your validation logic here.
Console.WriteLine("Text validated");
}
VB
Private Sub editControl1_TextChanged(sender As Object, e As System.EventArgs) Handles
editControl1.TextChanged
' Do not start the timer as long as characters are being typed.
If Me.timer1.Enabled = True Then
Me.timer1.Stop()
End If
Me.timer1.Start()
End Sub 'editControl1_TextChanged
Private Sub timer1_Tick(sender As Object, e As System.EventArgs) Handles timer1.Tick
Me.ValidateText()
Me.timer1.Stop()
End Sub 'timer1_Tick
Private Sub ValidateText()
' Perform your validation logic here.
MessageBox.Show("Text validated")
End Sub 'ValidateText
::adCenter::