Class dgvTbNumericCell
Inherits DataGridViewTextBoxCell
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _
ByVal initialFormattedValue As Object, _
ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
AddHandler Me.DataGridView.EditingControl.TextChanged, AddressOf tb_TextChanged
End Sub
Public Overrides Sub DetachEditingControl()
MyBase.DetachEditingControl()
RemoveHandler Me.DataGridView.EditingControl.TextChanged, AddressOf tb_TextChanged
End Sub
Private Sub tb_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim tb As TextBox = sender ' or Me.DataGridView.EditingControl
tb.Text = System.Text.RegularExpressions.Regex.Replace(tb.Text, "\D", "")
tb.SelectionStart = tb.TextLength
End Sub
End Class