To add a custom eventhandler to your DataGridView Cell :
Private Sub grdVoor_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
Try
If grdVoor.Columns(grdVoor.CurrentCell.ColumnIndex).Name.ToLower = "stock" Then
AddHandler e.Control.KeyPress, AddressOf grdvoor_stock_keypress
End If
Catch ex As Exception
throw new exception(ex.message)
End Try
End Sub
Private Sub grdvoor_stock_keypress(sender As Object, e As KeyPressEventArgs)
'allow . and ,
If e.KeyChar = "." Then e.KeyChar = ","
'only 1 . or , allowed
If e.KeyChar = "," Then
If sender.text.contains(".") Or sender.text.contains(",") Then
Beep()
e.Handled = True
Exit Sub
End If
End If
'check length
If sender.text.length > 10 Then
Beep()
e.Handled = True
Exit Sub
End If
'check for valid key
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso e.KeyChar <> ","c Then
Beep()
e.Handled = True
End If
End Sub