Private Sub DGVAmount_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGVAmount.KeyPress
If DGVAmount.SelectedCells.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
Dim intMaxLength As Integer = 12 'Set your max length here
If dgvTxtBox Is Nothing = False Then
Dim str As String = dgvTxtBox.Text.ToString()
If Not str.Length < intMaxLength _
AndAlso Not e.KeyChar = ControlChars.Back Then
e.Handled = True
Beep()
Exit Sub
End If
End If
End If
End If
End Sub