Bonjour,
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 ?
Merci du coup de main
Gwendal
Version imprimable
Bonjour,
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 ?
Merci du coup de main
Gwendal
Bonjour.
Le mieux me semble d'utiliser une custom colonne basée sur un Maskedtextbox.
Celle de Microsoft ici :
http://msdn2.microsoft.com/fr-fr/lib...96(VS.85).aspx
Cdt.
Salut,
:?:? Lien mort sur le téléchargement...
http://msdn2.microsoft.com/fr-fr/lib...3x(VS.85).aspx
J'ai recherché sur le net mais rien...
Quelqu'un aurait-il la source.... merci
Gdal
:yaisse2: J'ai trouvé sur un autre forum (MSDN)
VoilàCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 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 End If Catch ex As Exception End Try End Sub
Gdal