SUpprimer item d'une listbox

La Biode Messages postés 133 Date d'inscription jeudi 5 août 2004 Statut Membre Dernière intervention 11 août 2010 - 4 mai 2006 à 20:19
La Biode Messages postés 133 Date d'inscription jeudi 5 août 2004 Statut Membre Dernière intervention 11 août 2010 - 4 mai 2006 à 21:33
Voilà j'aimerai bien savoir comment l'on fait pour supprimer un item dans une listbox. Car j'ai un programme qui trie des fichiers celon leur extension et j'aimerai si elle ne correspond pas a un type de fichier que l'utilisateur a sélectionné cela le supprime de la liste.

J'ai ce code mais le problème c'est que rien ne se passe :

If Combo1.Text = "Image " Then
For i = 0 To List2.ListCount - 1
If fichierext = Right(List2.Text, 4) <> ".jpg" Then
List2.RemoveItem List2.ListIndex
End If
Next
End If

Voilà si vous pouvez m'aider.

Merci La Biode.

6 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
4 mai 2006 à 21:17
Salut,

Langage VB6:

- tu dois faire ta boucle à l'envers sinon tes index ne vont plus correspondre

- il faut utiliser i dans la boucle pour pointer sur la ligne correspondante

List2.List(i)

List2.RemoveItem i

- pas clair ce test:

If fichierext = Right(List2.Text, 4) <> ".jpg" Then ...





If Combo1.Text = "Image " Then
For i = List2.ListCount - 1 To 0 Step -1
If Right(List2.List(i), 4) <> ".jpg" Then
List2.RemoveItem i
End If
Next
End If

Daniel
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
4 mai 2006 à 21:22
ou alors si l'extension est choisie par l'utilisateur:

fichierext = ".jpg"



If Right(List2.List(i), 4) <> fichierext Then

Daniel
0
Profil bloqué
4 mai 2006 à 21:24
bonjour

La variable de boucle i sert d'index pour la ligne
il faut la mettre à List2.text comme indice ainsi que comme paramètre pour la méthode Removeitem

If Combo1.Text = "Image " Then
For i = 0 To List2.ListCount - 1
If Right(List2.Text(i), 4) <> ".jpg" Then
List2.RemoveItem i
List2.refresh
End If
Next
End If

en espérant avoir solutionné votre problème
A+

GRENIER Alain[8D]
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
4 mai 2006 à 21:26
zut, j'ai encore oublié:

If Right$(List2.List(i), 4) <> fichierext Then

Daniel
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Profil bloqué
4 mai 2006 à 21:27
comme dit Gobillot la boucle doit e^tre faite à l'envers : je n'y ai point pensé

GRENIER Alain[8D]
0
La Biode Messages postés 133 Date d'inscription jeudi 5 août 2004 Statut Membre Dernière intervention 11 août 2010
4 mai 2006 à 21:33
Merci bien a vous deux mon problème est résolut.
0
Rejoignez-nous