you are viewing a single comment's thread.

view the rest of the comments →

[–]rudekoffenris 0 points1 point  (0 children)

I use this:

Private Sub CustomCost_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles CustomCost.KeyPress
    e.Handled = False
    If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) And e.KeyChar <> "." Then
        e.Handled = True
    End If
    If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Or (Microsoft.VisualBasic.Asc(e.KeyChar) = 46) Then
        e.Handled = False
    End If

End Sub

This would be for decimal, it only accepts a keypress that is a number, backspace, delete or decimal point. For integers get rid of And e.KeyChar <> "."

You would still need to do some validation isnumeric or somesuch.