Gwendal3
Messages postés60Date d'inscriptionsamedi 4 mars 2006StatutMembreDernière intervention15 août 2011
-
26 févr. 2008 à 22:49
Gwendal3
Messages postés60Date d'inscriptionsamedi 4 mars 2006StatutMembreDernière intervention15 août 2011
-
28 févr. 2008 à 21:32
Bonsoir,
Comment dans les cellules d'une colonne d'un DataGrdView n'autoriser que la saisie de chiffres ??
Ou comment récupérer l'évènement PressKey d'une cellule ?
Gwendal3
Messages postés60Date d'inscriptionsamedi 4 mars 2006StatutMembreDernière intervention15 août 2011 28 févr. 2008 à 21:32
re,
J'ai trouvé sur un forum (MSDN)
@+
Gdal
Private Sub CheckCell (ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim KeyAscii As Short = Asc(e.KeyChar)
'...
'... code to check the input
'...
If KeyAscii = 0 Then
e.Handled = True
End If
End Sub
' pass control to the keyPress-Event of active cell
Private Sub DataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView.EditingControlShowing
Try
'...to us this is a criteria, to only find and check "numeric" cells
If e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight Then
AddHandler e.Control.KeyPress, AddressOf CheckCell
Else
'in order to prevent "optical problems", we had to call the removeHandler twice
RemoveHandler e.Control.KeyPress, AddressOf CheckCell
RemoveHandler e.Control.KeyPress, AddressOf CheckCell