Bonjour a tous,
J'ai refais de manière plus lisible mon formulaire.
Mon problème, c'est via mes Listbox, sélectionner des critères dans chaque ListBox pour filtrer ma Listview.
Je n'arrive a mettre en place cela dans mon USER lie a Sub affiche.
Avec une Lisbox j'avais ce code qui marche bien et je souhaite l'adapter pour une Listview: dans mon formulaire, j'ai 9 Listbox.
Private Sub UserForm_Initialize()
Dim j As Byte
Dim d
Dim i As Long
Dim LO
Macro1
SortData_1
nomtableau = "Tableau1"
nbcol = Range(nomtableau).ListObject.ListColumns.Count
TblBD = Range(nomtableau).Resize(, nbcol + 1).Value
For j = 1 To 2
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbTextCompare
For i = LBound(TblBD) To UBound(TblBD)
d(TblBD(i, j + 4)) = vbNullString
Next i
Me.Controls("ChoixListBox" & j).List = liste_triée_sans_doublons(d.keys)
Next j
For j = 3 To 16
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbTextCompare
For i = LBound(TblBD) To UBound(TblBD)
d(TblBD(i, j + 7)) = vbNullString
Next i
Me.Controls("ChoixListBox" & j).List = liste_triée_sans_doublons(d.keys)
Next j
For j = 1 To 30
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbTextCompare
For i = LBound(TblBD) To UBound(TblBD)
Select Case j
Case 27, 28, 29, 30: d(TblBD(i, j - 26)) = vbNullString
Case Else: d(TblBD(i, j)) = vbNullString
End Select
Next i
Me.Controls("ComboBox" & j).List = liste_triée_sans_doublons(d.keys)
Next j
With Me.ListBox20
.ColumnCount = 31 'à par nbcol sir c'est tout le tableau qui est à prendre dans la listbox
.List = TblBD
.ColumnWidths = "75;300;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0"
End With
End Sub
Sub Affiche()
Dim i
Dim j As Byte, k As Byte
Dim dchoisis(1 To 16)
For j = 1 To 16
Set dchoisis(j) = CreateObject("Scripting.Dictionary")
For i = 0 To Me.Controls("ChoixListBox" & j).ListCount - 1
If Me.Controls("ChoixListBox" & j).Selected(i) Then dchoisis(j)(Me.Controls("ChoixListBox" & j).List(i, 0)) = ""
Next i
Next j
Dim n
Dim liste()
Dim tmp(1 To 17)
For i = LBound(TblBD) To UBound(TblBD)
tmp(1) = TblBD(i, 5)
tmp(2) = TblBD(i, 6)
For j = 3 To 16
tmp(j) = TblBD(i, j + 7)
Next j
tmp(17) = TblBD(i, 1)
If (dchoisis(1).Exists(tmp(1)) Or dchoisis(1).Count = 0) _
And (dchoisis(2).Exists(tmp(2)) Or dchoisis(2).Count = 0) _
And (dchoisis(3).Exists(tmp(3)) Or dchoisis(3).Count = 0) _
And (dchoisis(4).Exists(tmp(4)) Or dchoisis(4).Count = 0) _
And (dchoisis(5).Exists(tmp(5)) Or dchoisis(5).Count = 0) _
And (dchoisis(6).Exists(tmp(6)) Or dchoisis(6).Count = 0) _
And (dchoisis(7).Exists(tmp(7)) Or dchoisis(7).Count = 0) _
And (dchoisis(8).Exists(tmp(8)) Or dchoisis(8).Count = 0) _
And (dchoisis(9).Exists(tmp(9)) Or dchoisis(9).Count = 0) _
And (dchoisis(10).Exists(tmp(10)) Or dchoisis(10).Count = 0) _
And (dchoisis(11).Exists(tmp(11)) Or dchoisis(11).Count = 0) _
And (dchoisis(12).Exists(tmp(12)) Or dchoisis(12).Count = 0) _
And (dchoisis(13).Exists(tmp(13)) Or dchoisis(13).Count = 0) _
And (dchoisis(14).Exists(tmp(14)) Or dchoisis(14).Count = 0) _
And (dchoisis(15).Exists(tmp(15)) Or dchoisis(15).Count = 0) _
And (dchoisis(16).Exists(tmp(16)) Or dchoisis(16).Count = 0) Then
n = n + 1
ReDim Preserve liste(1 To nbcol + 1, 1 To n)
For k = 1 To nbcol + 1
liste(k, n) = TblBD(i, k)
Next k
End If
Next i
If n > 0 Then Me.ListBox20.Column = liste Else Me.ListBox20.Clear
End Sub
Private Sub ChoixListBox1_change()
Affiche
End Sub
Private Sub ChoixListBox2_change()
Affiche
End Sub
Private Sub ChoixListBox3_change()
Affiche
End Sub
Private Sub ChoixListBox4_change()
Affiche
End Sub
Private Sub ChoixListBox5_change()
Affiche
End Sub
Private Sub ChoixListBox6_change()
Affiche
End Sub
Private Sub ChoixListBox7_change()
Affiche
End Sub
Private Sub ChoixListBox8_change()
Affiche
End Sub
Private Sub ChoixListBox9_change()
Affiche
End Sub
Private Sub ChoixListBox10_change()
Affiche
End Sub
Private Sub ChoixListBox11_change()
Affiche
End Sub
Private Sub ChoixListBox12_change()
Affiche
End Sub
Private Sub ChoixListBox13_change()
Affiche
End Sub
Private Sub ChoixListBox14_change()
Affiche
End Sub
Private Sub ChoixListBox15_change()
Affiche
End Sub
Private Sub ChoixListBox16_change()
Affiche
End Sub
En vous remerciant pour votre aide,
a+