KeyPress Validation with decimal.

  • Thread starter Thread starter pk.yadav
  • Start date Start date
P

pk.yadav

Guest
I am Currently using this code for validation of a textbox..

Private Sub EximTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
Select Case m_ETMasktype
Case validationtypes.numbers
If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
e.Handled = False
End If
Case validationtypes.Decimals
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso e.KeyChar <> "." Then
e.Handled = True
Else
If e.KeyChar = "." And Me.Text.IndexOf(".") <> -1 Then
e.Handled = True
ElseIf e.KeyChar = "." Then
e.Handled = False
ElseIf Char.IsDigit(e.KeyChar) Then
If Me.Text.IndexOf(".") <> -1 Then
If Me.Text.Length >= Me.Text.IndexOf(".") + (pointdecimal + 1) Then 'replace 2 for greater numbers after decimal point
e.Handled = True
End If
End If
End If
End If
Case validationtypes.UpperCase
If Char.IsLower(e.KeyChar) Then
e.Handled = True
SendKeys.Send(Char.ToUpper(e.KeyChar))
End If
End Select

End Sub


now my textbox is set to select all text on focus " Me.SelectAll()"

now issue is when there is a data in text box with decimal and all data is already selected, i can not enter new figure before deleting the existing data.


all i am trying to is enter data when old date is selected.

when there is no decimal it automatically delete the existing data and i can strait away insert the data


I hope i am able to explain my issue.


Please help..



Pradeep Yadav (Social MSDN)

Continue reading...
 
Back
Top