Private dgvTxtBox As DataGridViewTextBoxEditingControl
Private Sub DGVAmount_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DGVAmount.EditingControlShowing
Dim ctrlName As String = e.Control.GetType.Name
If ctrlName = "DataGridViewTextBoxEditingControl" Then
dgvTxtBox = CType(e.Control, DataGridViewTextBoxEditingControl)
AddHandler dgvTxtBox.KeyPress, AddressOf DGVAmount_KeyPress
dgvTxtBox.Enabled = True
End If
End Sub
‘------------------------------------------------------------------
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
If dgvTxtBox Is Nothing = False Then
Dim str As String = dgvTxtBox.Text.ToString()
If Asc(e.KeyChar) > 47 And Asc(e.KeyChar) <= 57 Or e.KeyChar = "." Or Asc(e.KeyChar) = 8 Then
If str.Contains(".") Then
If Asc(e.KeyChar) = 46 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End If
End If
End If
End Sub