I need to come up with a way to restrict the user from entering anything other than 1
or 2
in a column in my dgv. I have it so the user is restricted
many different ways to approach this .. i use RegEx
with this
Private Function CleanInputNumber(ByVal str As String) As String
Return System.Text.RegularExpressions.Regex.Replace(str, "[a-zA-Z\b\s-.]", "")
End Function
and this
Private Function CleanInputAlphabet(ByVal str As String) As String
Return System.Text.RegularExpressions.Regex.Replace(str, "[0-9\b\s-]", "")
End Function
you should figure it out
and this is the event i use
Private Sub xDataGridView_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles xDataGridView.CellValidating
If xDataGridView.CurrentRow.Cells("xColumn").IsInEditMode Then
Dim c As Control = xDataGridView.EditingControl
Select Case xDataGridView.Columns(e.ColumnIndex).Name
Case "xColumn"
c.Text = CleanInputNumber(c.Text)
'Case "yColumn"
' c.Text = CleanInputAlphabet(c.Text)
End Select
End If
End Sub