[VB.NET] afficher 1 seul item dans une listbox, ça marche avec plusieurs pourtant...
J'ai créé une procédure pour afficher des éléments (des noms d'images dans mon cas) dans une listbox, cela marche parfaitement quand j'ai au moins deux éléments (ils sont visible dans la listbox), mais jamais pour un seul élément, il est TOUJOURS invisible.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Private Sub load_pics(ByVal selectFirst As Boolean)
If Directory.Exists(Application.StartupPath.Substring(0, 1) & ":\vbproject\cads\" & currentfolderselected) Then
Dim di As New DirectoryInfo(Application.StartupPath.Substring(0, 1) & ":\vbproject\cads\" & currentfolderselected)
' Create an array representing the files in the current directory.
Dim fi As FileInfo() = di.GetFiles()
Dim fiTemp As FileInfo
ProfileList.Items.Clear() 'clean the list
ProfileList.BeginUpdate() 'add pics, block the update of the listbox first
Dim extensionpath As String
Dim tampon As String
For Each fiTemp In fi
extensionpath = fiTemp.ToString
tampon &= extensionpath & vbNewLine
extensionpath = Mid(extensionpath, extensionpath.LastIndexOf(".") + 2, 3)
If (extensionpath = "gif" Or extensionpath = "bmp" Or extensionpath = "jpg" _
Or extensionpath = "GIF" Or extensionpath = "BMP" Or extensionpath = "JPG") Then ProfileList.Items.Add(fiTemp.ToString)
Next fiTemp
ProfileList.EndUpdate()
Console.Write(vbNewLine & tampon & ProfileList.Items.Count)
If ProfileList.Items.Count > 0 And selectFirst Then ProfileList.SetSelected(0, True) 'if selectFirst then, select first item of the listbox
End If
End Sub |
La variable fiTemp contient bien quelque chose quand il n'y a qu'un élément et ProfileList.Items.Count = 1 aussi.
Je crois que cela est dû à un problème de rafraichissement de la listbox. J'ai pourtant essayé de faire ça avec les méthodes ProfileList.Refresh() et ProfileList.Update(), mais sans succès.
Quelqu'un a-t'il déjà le problème ? Merci d'avance pour vos réponses.