This method woorked fine with WinForms using vb.NET.
The problem comes wen I use it in WPF.
Is there a better method of carrying out validation of textbox in WPF forms ??
Private Sub txtname_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles txtname.PreviewKeyDown Dim no As Integer Dim s As String = e.Key.ToString() Dim chars As Char() = s.ToCharArray() Dim chr As Char = chars(0) no = System.Convert.ToInt32(chr) If (no >= 65 And no <= 90) Then e.Handled = True Else txtname.Text = "" End If End Sub
The problem in the above code is that it doesn't accept any characters even if e.Handled=True