how to restrict user input to numbers only

aman_VB

Member
Joined
Apr 27, 2010
Messages
23
Programming Experience
1-3
I am sure there is a way to do what I am trying to accomplish. Numbers only.

VB.NET:
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        If Me.DataGridView1.Columns(e.ColumnIndex).HeaderText = "Smoothing" Then
            If Not DataGridView1.CurrentCell.Value.IndexOfAny("+-.0123456789") <> -1 Then
                Exit Sub
            End If
            'Do something
        End If
    End Sub


Now if you enter ABC123, it still show the ABC123. How do you re-write the sub such that if the user enters a combination of numbers and non-numbers, the sub exits and the cell shows nothing?

Thanks and Regards
 
Back
Top