'******************************************************************************************************************************
'Ajout des données dans la listview2
'******************************************************************************************************************************
Private Sub CmbAjouter_Click()
Dim lg As Long, cl As Long, i As Long, j As Long
Dim T As Variant
Dim derlig As Long
If Not IsVide Then
'On crée une Nouvelle Ligne, on met la valeur dans la première colonne de cette Ligne
With Me.ListView2.ListItems.Add(, , Me.CmB_Type.Value)
.ForeColor = Color_Lvw 'On la colore
.ListSubItems.Add(, , Me.TextBoxLIGNE.Value).ForeColor = .ForeColor
.ListSubItems.Add(, , Me.TextBoxVOIE.Value).ForeColor = .ForeColor
.ListSubItems.Add(, , Me.TextBoxDU_PK.Value).ForeColor = .ForeColor
.ListSubItems.Add(, , Me.TextBoxAU_PK.Value).ForeColor = .ForeColor
.ListSubItems.Add(, , Me.TextboxCAUSES.Value).ForeColor = .ForeColor
.ListSubItems.Add(, , Me.CmB_Categories).ForeColor = .ForeColor
.Selected = True
End With
With ListView2
lg = .ListItems.Count
cl = .ColumnHeaders.Count
ReDim T(1 To lg, 1 To cl + 1)
For i = 1 To lg
T(i, 1) = .ListItems(i).Text
For j = 1 To cl - 1
T(i, j + 1) = .ListItems(i).ListSubItems(j).Text
Next j
Next i
End With
With Sheets("JOURNAL")
derlig = .Cells(Rows.Count, 1).End(xlUp).Row ' dernière ligne occupée
For i = 1 To lg ' boucle sur les lignes du tableau
' derlig + i => pour incrémenter au fur et à mesure les lignes de la feuille
.Range("A" & derlig + i) = T(i, 1) 'Categories
.Range("B" & derlig + i) = T(i, 2) 'Type
.Range("C" & derlig + i) = T(i, 3) 'Lignz
.Range("D" & derlig + i) = T(i, 4) 'Voie
.Range("E" & derlig + i) = T(i, 5) 'Du PK
.Range("F" & derlig + i) = T(i, 6) 'Au PK
.Range("H" & derlig + i) = T(i, 8) 'Localisation
Next i
End With
End If
Effacer
End Sub