Modification en Cascade dans Listview

Bonjour à toutes et tous,

j'ai un combobox dans lequel je choisi un Pièces, quand je sélectionne cela me renvoi dans le listview les références qui composent cette pièces ainsi que la quantité de chacune de ces références.

je souhaiterai modifier ces quantités à travers la textbox à côté du combobox.

je choisis la pièce dans le combobox, et je souhaite dire dans la textbox combien j'ai de cette pièce et ainsi cela change la quantité des références qui constituent cette pièce.

pas certain de réussir à me faire comprendre.

Bonjour,

pas certain de réussir à me faire comprendre.

Effectivement !

Quand tu choisis une pièce dans le 1er ComboBox, la quantité doit être changée pour toutes les références attachées à cette pièce ou pour une en particulier ?

oui c'est ça. la quantité doit changer pour toutes les références attachées à cette pièce.

Re,

Je te re-poste tout le code car j'ai fait plusieurs modifs comme l'impossibilité d'entrer d'autres caractères que les chiffres de 0 à 9 dans les TextBox et prendre en compte les quantités entrées dans chaque TextBox lors du chargement de la ListView au clic des ComboBox procédure "Remplir()". C'est la procédure Quantite() qui inscrit dans la ListView :

Dim f, Tbl(), Ncol

Private Sub CommandButton2_Click()
T1 = 0
T2 = 0
T3 = 0
   With ListView1
   'Boucle sur toutes les lignes
     For Z = 1 To .ListItems.Count
         If IsNumeric(.ListItems(Z).ListSubItems(4).Text) Then
            If .ListItems(Z).ListSubItems(6).Text = "x" Then T1 = T1 + Val(.ListItems(Z).ListSubItems(4).Text)
            If .ListItems(Z).ListSubItems(7).Text = "x" Then T2 = T2 + Val(.ListItems(Z).ListSubItems(4).Text)
            If .ListItems(Z).ListSubItems(8).Text = "x" Then T3 = T3 + Val(.ListItems(Z).ListSubItems(4).Text)
         End If
      Next Z
   End With
      TextBox1.Value = T1
      TextBox2.Value = T2
      TextBox3.Value = T3
End Sub

Private Sub UserForm_Initialize()
With Sheets("Ensemble")
    ComboBox1.List = .Range("B1:B" & .Range("B65536").End(xlUp).Row).Value
    ComboBox2.List = .Range("D1:D" & .Range("D65536").End(xlUp).Row).Value
    ComboBox3.List = .Range("F1:F" & .Range("F65536").End(xlUp).Row).Value
    ComboBox4.List = .Range("H1:H" & .Range("H65536").End(xlUp).Row).Value
End With

 Set f = Sheets("Pieces")
   Set d = CreateObject("scripting.dictionary")
   Tbl = f.Range("A2:I" & f.[A65000].End(xlUp).Row).Value
   Ncol = UBound(Tbl, 2)
   For I = LBound(Tbl) To UBound(Tbl)
    If Tbl(I, 2) <> "" Then d(Tbl(I, 2)) = ""
   Next I
   temp = d.keys
   'Call Tri(temp, LBound(temp), UBound(temp))
   'Me.ComboBox1.List = temp

   '---listview
    With Me.ListView1
        With .ColumnHeaders
           .Clear
           For K = 1 To Ncol
             .Add , , f.Cells(1, K), f.Columns(K).Width * 0.9
           Next K
        End With
        .Gridlines = True
        .View = lvwReport
        ligne = 1
       For I = 1 To UBound(Tbl)
         ' .ListItems.Add , , Tbl(i, 1)
          For K = 2 To Ncol
           ' .ListItems(ligne).ListSubItems.Add , , Tbl(i, k)
          Next K
          ligne = ligne + 1
        Next I
    End With

Dim Z As Integer

End Sub

Private Sub ComboBox1_Click()

    Remplir

End Sub

Private Sub ComboBox2_Click()

    Remplir

End Sub

Private Sub ComboBox3_Click()

    Remplir

End Sub

Private Sub ComboBox4_Click()

    Remplir

End Sub
Private Sub TextBox4_Change()

    If TextBox4.Text = "" Then Exit Sub
    Quantite ComboBox1, TextBox4

End Sub

Private Sub TextBox4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    Select Case KeyAscii

        Case 48 To 57
        Case Else: KeyAscii = 0

    End Select

End Sub

Private Sub TextBox5_Change()

    If TextBox5.Text = "" Then Exit Sub
    Quantite ComboBox2, TextBox5

End Sub

Private Sub TextBox5_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    Select Case KeyAscii

        Case 48 To 57
        Case Else: KeyAscii = 0

    End Select

End Sub

Private Sub TextBox6_Change()

    If TextBox6.Text = "" Then Exit Sub
    Quantite ComboBox3, TextBox6

End Sub

Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    Select Case KeyAscii

        Case 48 To 57
        Case Else: KeyAscii = 0

    End Select

End Sub

Private Sub TextBox7_Change()

    If TextBox7.Text = "" Then Exit Sub
    Quantite ComboBox4, TextBox7

End Sub

Private Sub TextBox7_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    Select Case KeyAscii

        Case 48 To 57
        Case Else: KeyAscii = 0

    End Select

End Sub

Sub Remplir()

    Dim Lig As Long
    Dim J As Long
    Dim K As Long
    Dim C As Long

    With Me.ListView1

        .ListItems.Clear
        J = 1

        If ComboBox1.Text <> "" Then

            For Lig = 1 To UBound(Tbl)

                If Tbl(Lig, 2) = ComboBox1.Text Then

                    .ListItems.Add , , Tbl(Lig, 1)

                    For K = 2 To Ncol

                        If K = 6 And TextBox4.Text <> "" Then
                            .ListItems(J).ListSubItems.Add , , TextBox4.Text
                        Else
                            .ListItems(J).ListSubItems.Add , , Tbl(Lig, K)
                        End If

                    Next K

                    J = J + 1
                    C = C + 1

                End If

            Next Lig

            Me.Label5.Caption = C: C = 0

        End If

        If ComboBox2.Text <> "" Then

            For Lig = 1 To UBound(Tbl)

                If Tbl(Lig, 2) = ComboBox2.Text Then

                    .ListItems.Add , , Tbl(Lig, 1)

                    For K = 2 To Ncol

                        If K = 6 And TextBox5.Text <> "" Then
                            .ListItems(J).ListSubItems.Add , , TextBox5.Text
                        Else
                            .ListItems(J).ListSubItems.Add , , Tbl(Lig, K)
                        End If

                    Next K

                    J = J + 1
                    C = C + 1

                End If
            Next Lig

            Me.Label6.Caption = C: C = 0

        End If

        If ComboBox3.Text <> "" Then

            For Lig = 1 To UBound(Tbl)

                If Tbl(Lig, 2) = ComboBox3.Text Then

                    .ListItems.Add , , Tbl(Lig, 1)

                    For K = 2 To Ncol

                        If K = 6 And TextBox6.Text <> "" Then
                            .ListItems(J).ListSubItems.Add , , TextBox6.Text
                        Else
                            .ListItems(J).ListSubItems.Add , , Tbl(Lig, K)
                        End If

                    Next K

                    J = J + 1
                    C = C + 1

                End If
            Next Lig

            Me.Label7.Caption = C: C = 0

        End If

        If ComboBox4.Text <> "" Then

            For Lig = 1 To UBound(Tbl)

                If Tbl(Lig, 2) = ComboBox4.Text Then

                    .ListItems.Add , , Tbl(Lig, 1)

                    For K = 2 To Ncol

                        If K = 6 And TextBox7.Text <> "" Then
                            .ListItems(J).ListSubItems.Add , , TextBox7.Text
                        Else
                            .ListItems(J).ListSubItems.Add , , Tbl(Lig, K)
                        End If

                    Next K

                    J = J + 1
                    C = C + 1

                End If
            Next Lig

            Me.Label8.Caption = C: C = 0

        End If

    End With

End Sub

Sub Quantite(Cmb As MSForms.ComboBox, Txt As MSForms.TextBox)

    Dim I As Long

    With ListView1

        For I = 1 To .ListItems.Count

            If .ListItems(I).ListSubItems(1).Text = Cmb.Text Then
                .ListItems(I).ListSubItems(5).Text = Txt.Text
            End If

        Next I

    End With

End Sub

Super, je vais tester tout ça.

Merci champion. Bon We.

cela fonctionne parfaitement.

merci encore

Bonjour,

C'est avec plaisir !

bon Week-end

Rechercher des sujets similaires à "modification cascade listview"