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
| Private Sub CommandButton1_Click()
'----- remplissage ListView------------------------
With ListView1
With .ColumnHeaders
.Clear
'ajout des entete et dimention des colonnes For i = 1 To 5
For c = 1 To 5
.Add c, "col" & c, Cells(1, c), Round(Sheets(1).Cells(1, c).Width)
Next
End With
'Remplissage de la 1ere colonne (création de 3 lignes)
With .ListItems
For i = 2 To 11
.Add i - 1, , Sheets(1).Cells(i, 1)
If Len(Cells(i, c)) * 4 > ListView1.ColumnHeaders(1).Width Then ListView1.ColumnHeaders(1).Width = Len(Cells(i, c)) * 4
For c = 2 To 5
ListView1.ListItems(i - 1).ListSubItems.Add c - 1, , Cells(i, c)
If Cells(i, c) = "activated" Then ListView1.ListItems(i - 1).ListSubItems(c - 1).ForeColor = RGB(255, 0, 0)
If Cells(i, c) = "cadre" Then ListView1.ListItems(i - 1).ListSubItems(c - 1).ForeColor = RGB(100, 150, 0)
If Len(Cells(i, c)) * 5 > ListView1.ColumnHeaders(c).Width Then ListView1.ColumnHeaders(c).Width = Len(Cells(i, c)) * 5
Next
Next
End With
'------------------------------------------------
'fonctionne en vb6 mais pas en vba
'For Each lvi In ListView1.ListItems
'If Index Mod 2 = 0 Then
'lvi.BackColor = vbYellow
'Else
'lvi.BackColor = vbCyan
'End If
'Next
'--------------------------------------------------
End With
'Spécifie l'affichage en mode "Détails"
ListView1.View = lvwReport
End Sub |
Partager