كود :
Private Sub DataGridView1_GotFocus(sender As Object, e As EventArgs) Handles DataGridView1.GotFocus
RemoveHandler CType(sender, DataGridView).EditingControlShowing, AddressOf DataGridView1_EditingControlShowing
AddHandler CType(sender, DataGridView).EditingControlShowing, AddressOf DataGridView1_EditingControlShowing
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
If sender.CurrentCell.ColumnIndex = 0 Then ' <<<< ColumnIndex
Dim TB = CType(e.Control, TextBox)
RemoveHandler TB.KeyPress, AddressOf DataGridView1_KeyPress
AddHandler TB.KeyPress, AddressOf DataGridView1_KeyPress
End If
End Sub
Private Sub DataGridView1_KeyPress(sender As Object, e As KeyPressEventArgs)
' حدث كتابة أرقام فقط في الحقل
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 46 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
If sender.Text.Contains(".") Then
If e.KeyChar = "." Then
e.Handled = True
End If
End If
End Sub