IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Checkbox en DataGridView état Checked (True)


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2012
    Messages : 36
    Par défaut Checkbox en DataGridView état Checked (True)
    Bonjour,
    J'ai un DataGridView avec en colonne de type checkbox. Je souhaiterai que lorsque je coche le checkbox
    des cells reviens reviens 0.00

    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
     Private Sub DView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DView.CellClick
     
    For Each row As DataGridViewRow In DView.Rows
                Dim isSelected As Boolean = Convert.ToBoolean(row.Cells("checkBoxColumn").Value)
                If isSelected Then
                    For i As Integer = 0 To Me.DView.Rows.Count - 1
                        Dim total As Integer = 0
                        Me.DView(5, i).Value = Format(Me.DView(5, i).Value * total, "0.00")
                        Me.DView(7, i).Value = Format(Me.DView(7, i).Value * total, "0.00")
                        Me.DView(8, i).Value = Format(Me.DView(8, i).Value * total, "0.00")
                        Me.DView(9, i).Value = Format(Me.DView(9, i).Value * total, "0.00")
                        Me.DView(10, i).Value = Format(Me.DView(10, i).Value * total, "0.00")
                        Me.DView(11, i).Value = Format(Me.DView(11, i).Value * total, "0.00")
                        Me.DView(12, i).Value = Format(Me.DView(12, i).Value * total, "0.00")
                        Me.DView(12, i).Value = Format(Me.DView(12, i).Value * total, "0.00")
                        Me.DView(13, i).Value = Format(Me.DView(13, i).Value * total, "0.00")
                        Me.DView(14, i).Value = Format(Me.DView(14, i).Value * total, "0.00")
                        Me.DView(15, i).Value = Format(Me.DView(15, i).Value * total, "0.00")
                        Me.DView(16, i).Value = Format(Me.DView(16, i).Value * total, "0.00")
                    Next
     
                End If
            Next
        End Sub
    Merci beaucoup et bonne journée.

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour

    code exemple .vb:
    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    Public Class Form2
        Private Produits As DataTable
        Private rnd As New Random
        Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Produits = GetTable()
            DGV.DataSource = Produits
            Me.DGV.Columns("PrixHT").DefaultCellStyle.Format = "F2" 'format virgule fixe 2 decimales
     
        End Sub
        Private Function GetTable() As DataTable
     
            Dim dt As New DataTable("produits")
            dt.Columns.Add("Quantite", GetType(Integer))
            dt.Columns.Add("PrixUnitaire", GetType(Double))
            dt.Columns.Add("PrixHT", GetType(Double))
            dt.Columns.Add("Verifier", GetType(Boolean))
            Dim dr As DataRow = dt.NewRow()
            For n As Integer = 1 To 10
     
                dr(0) = rnd.Next(10, 20)
                dr(1) = Math.Round(rnd.NextDouble() * 100, 2)
                dr(2) = dr(0) * dr(1) 'PrixHT=Quantite*PrixUnitaire
                dr(3) = False
                dt.Rows.Add(dr)
                dr = dt.NewRow()
            Next
            Return dt
        End Function
     
        Private Sub DGV_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellClick
            If (e.RowIndex < 0 Or e.ColumnIndex < 0) Then Return
            Dim row As DataGridViewRow = DGV.Rows(e.RowIndex)
            Dim currRow As Integer = e.RowIndex
            Dim currCol As Integer = e.ColumnIndex
            Dim isSelected As Boolean = row.Cells("Verifier").Selected
            If isSelected Then
                Dim total As Integer = 0
                ClearChecked(total, currCol)
            End If
        End Sub
        Private Sub ClearChecked(tot As Double, col As Integer)
            For irow As Integer = 0 To DGV.Rows.Count - 1
                Me.DGV(col - 1, irow).Value = Format(Me.DGV(col - 1, irow).Value * tot, "F2")
     
            Next
     
        End Sub
    End Class


    bon code..
    ..

  3. #3
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2012
    Messages : 36
    Par défaut
    Bonjour, et merci mabrouki
    dans la cellule précise dans la ligne cocher seulement dans le ligne sélectionnée et pas dans toute la colonne.
    Par exemple cellule N 2 de la ligne cocher.
    J'ai changé le code mais il na pas marché.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     Private Sub ClearChecked(ByVal tot As Double, ByVal col As Integer)
            For irow As Integer = 0 To DView.Rows.Count - 1
                ' Me.DView(col - 1, irow).Value = Format(Me.DView(col - 1, irow).Value * tot, "F2")
                Me.DView(2, irow).Value = Format(Me.DView(2, irow).Value * tot, "f2")
            Next
        End Sub

  4. #4
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    Il faudrait savoir d'abord ce que tu veux exactement car le premier code posté "balaie" toutes les lignes du DGV et non la ligne en cours.....

  5. #5
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2012
    Messages : 36
    Par défaut
    bonsoir mabrouki,
    je veux exactement que code du DGV marche avec des cellule précises dans la ligne en cours (la ligne cocher du chekbox)
    par ex dans la ligne sectionne (cheked=true) la valeur du cellule 2, 3 ... devient 0.00 quelque cellules et pas toute la ligne si c'est possible
    merci

  6. #6
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    1/ ce code au début abrège les "souffrances" concernant le format des cellules:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
       Me.DGV.Columns("PrixHT").DefaultCellStyle.Format = "F2" 'format virgule fixe 2 decimales
            Me.DGV.Columns("PrixTVA").DefaultCellStyle.Format = "F2" 'format virgule fixe 2 decimales
    2/ l'indexation des Cells cibles par le nom des colonnes fait le même boulot.
    3/ dans le cas que tu cherches à résoudre ,e.RowIndex (ligne en cours) est ton ami.

    code .vb revu qui fera ton bonheur:
    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
     
    Public Class Form3
        Private Produits As DataTable
        Private rnd As New Random
        Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Produits = GetTable()
            DGV.DataSource = Produits
            Me.DGV.Columns("PrixHT").DefaultCellStyle.Format = "F2" 'format virgule fixe 2 decimales
            Me.DGV.Columns("PrixTVA").DefaultCellStyle.Format = "F2" 'format virgule fixe 2 decimales
     
        End Sub
        Private Function GetTable() As DataTable
     
            Dim dt As New DataTable("produits")
            dt.Columns.Add("Quantite", GetType(Integer))
            dt.Columns.Add("PrixUnitaire", GetType(Double))
            dt.Columns.Add("PrixHT", GetType(Double))
            dt.Columns.Add("TauxTVA", GetType(Double))
            dt.Columns.Add("PrixTVA", GetType(Double))
            dt.Columns.Add("Verifier", GetType(Boolean))
            Dim dr As DataRow = dt.NewRow()
            Dim tauxTVA As Double = 15 'pourcentage
            For n As Integer = 1 To 10
     
                dr("Quantite") = rnd.Next(10, 20)
                dr("PrixUnitaire") = Math.Round(rnd.NextDouble() * 100, 2)
                dr("PrixHT") = dr("Quantite") * dr("PrixUnitaire") 'PrixHT=Quantite*PrixUnitaire
                dr("TauxTVA") = tauxTVA
                dr("PrixTVA") = Math.Round(dr("PrixHT") + dr("PrixHT") * dr("TauxTVA") / 100.0, 2) 'PrixTVA=PrixHT+PrixHT*TauxTVA/100.0
                dr("Verifier") = False
     
                dt.Rows.Add(dr)
                dr = dt.NewRow()
            Next
            Return dt
        End Function
     
        Private Sub DGV_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellClick
            If (e.RowIndex < 0 Or e.ColumnIndex < 0) Then Return
            Dim row As DataGridViewRow = DGV.Rows(e.RowIndex)
            Dim isSelected As Boolean = row.Cells("Verifier").Selected
            If isSelected Then
                Dim total As Integer = 0
                ClearChecked(total, e.RowIndex)
            End If
        End Sub
        Private Sub ClearChecked(tot As Double, irow As Integer)
            Me.DGV.Rows(irow).Cells("PrixHT").Value = 0.0
            Me.DGV.Rows(irow).Cells("PrixTVA").Value = 0.0
     
     
        End Sub
    End Class

    bon code....

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 7
    Dernier message: 08/04/2020, 15h26
  2. [VB.NET] Checkbox dans DataGridView
    Par horzy dans le forum Windows Forms
    Réponses: 6
    Dernier message: 09/02/2009, 16h24
  3. CheckBox avec 3 états
    Par Julius_Dev dans le forum AWT/Swing
    Réponses: 7
    Dernier message: 22/11/2006, 17h39
  4. [C#] CheckBox et différents états coché
    Par Neitsa dans le forum Windows Forms
    Réponses: 2
    Dernier message: 15/05/2006, 00h01
  5. Réponses: 7
    Dernier message: 08/03/2006, 16h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo