Bonjour,
Ce programme permet de pouvoir utiliser le point du pavé numérique car cela le remplace par une virgule.
Avec le labelb2 cela marche nickel, maintenant je voudrais l'adapter aux valeurs entrées dans le datagridview ici la colonne : (datagridview1.rows().cells(Coefficientimpermeabilisation)) mais je ne trouve pas comment faire. L'erreur est donc seulement dans les 2 premières private sub.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Const K_FILTRE_DOUBLE As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.-+*/\()!:;"
 
    Private Sub DataGridView1.Rows().Cells("Coefficientimpermeabilisation").Value_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridView1.Rows().Cells("Coefficientimpermeabilisation").Value.KeyPress
        filtrerFrappe(sender, e, K_FILTRE_DOUBLE)
    End Sub
 
    Private Sub DataGridView1.Rows().Cells("Coefficientimpermeabilisation").Value_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.Rows().Cells("Coefficientimpermeabilisation").Value.KeyUp
        CType(sender, TextBox).Text = CType(sender, TextBox).Text.Replace(".", ",")
        CType(sender, TextBox).SelectionStart = CType(sender, TextBox).Text.Length
    End Sub
 
    Private Sub Labelb2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Labelb2.KeyPress
        filtrerFrappe(sender, e, K_FILTRE_DOUBLE)
    End Sub
 
    Private Sub Labelb2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Labelb2.KeyUp
        CType(sender, TextBox).Text = CType(sender, TextBox).Text.Replace(".", ",")
        CType(sender, TextBox).SelectionStart = CType(sender, TextBox).Text.Length
    End Sub
 
    Private Sub filtrerFrappe(ByRef txtCourant As TextBox, ByRef e As System.Windows.Forms.KeyPressEventArgs, ByVal sFiltre As String)
        Dim bFiltrer As Boolean = False
        Dim cFrappe As String = e.KeyChar
        If cFrappe = "." Then cFrappe = ","
        bFiltrer = (sFiltre.IndexOf(cFrappe) = -1)
        If cFrappe = "," Then
            If txtCourant.Text.IndexOf(cFrappe) <> -1 Then
                bFiltrer = True
            Else
                bFiltrer = (txtCourant.Text.Length = 0)
            End If
        End If
        If cFrappe = ControlChars.Back Then bFiltrer = False
        e.Handled = bFiltrer
    End Sub
Voila mon message d'erreur :
DataGridView1 est déjà déclaré en tant que Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView dans ce class
Merci.