Surlignage d'item spécifique.

Résolu
cs_tictac08 Messages postés 10 Date d'inscription mercredi 5 décembre 2012 Statut Membre Dernière intervention 25 juillet 2013 - 17 juil. 2013 à 16:46
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 - 17 juil. 2013 à 21:01
Bonjour tout le monde

Alors voilà, je ne pense pas qu'avec ce titre très vague vous ayez compris


Bref, j'ai une listbox contenant plein de chemin de fichier d'un FTP (celui de l'utilisateur dans ce cas).

J'aimerai surligner toute la ligne d'un item séparément des autres, voici les couleur qui seront à utiliser :

- Jaune : En attente
- Vert : Download OK
- Rouge : Echec

Est-ce qu'il y aurait un moyen ?
Si on ne peux pas le faire avec une listbox normale, j'accepterai avec plaisir des liens qui permettent de télécharger des listbox comme ça.

5 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 344
17 juil. 2013 à 17:01
Bonjour,

Peut être avec DrawItem.

Regardez ICI

Cordialement,
Jordane
_____________________________________________________
Règles du forum à lire avant de poster une question : ICI
3
cs_tictac08 Messages postés 10 Date d'inscription mercredi 5 décembre 2012 Statut Membre Dernière intervention 25 juillet 2013
17 juil. 2013 à 17:34
Merci pour ce code, mais malheureusement je n'arrive pas à l'utiliser...

Quand j'appelle le Sub, je ne sais pas quelle valeur il faut pour "ByVal e As System.Windows.Forms.DrawItemEventArgs"
0
cs_tictac08 Messages postés 10 Date d'inscription mercredi 5 décembre 2012 Statut Membre Dernière intervention 25 juillet 2013
17 juil. 2013 à 19:40
Ah non c'est bon je viens de comprendre comme ça marche, il faut forcer la listbox a se redessiner.

Merci beaucoup jordane45
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 344
17 juil. 2013 à 20:36
Cordialement,
Jordane
_____________________________________________________
Règles du forum à lire avant de poster une question : ICI
0

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

Posez votre question
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
17 juil. 2013 à 21:01
Salut
pas si simple que ça
ici un petit ex avec un listbox nommé listbox1
Public Class Form1
    Private Structure pathinfo
        Public path As String
        Public status As Integer
    End Structure
    Private listpath As New List(Of pathinfo)
    Private Sub GetPath()
        Dim pathinfo As pathinfo
        pathinfo.path = "AAAAAAA0"
        pathinfo.status = 0
        listpath.Add(pathinfo)
        pathinfo.path = "BBBBBBBB0"
        pathinfo.status = 0
        listpath.Add(pathinfo)
        pathinfo.path = "CCCCCCCC0"
        pathinfo.status = 0
        listpath.Add(pathinfo)
        pathinfo.path = "DDDDDDDD0"
        pathinfo.status = 0
        listpath.Add(pathinfo)
        pathinfo.path = "AAAAAAA1"
        pathinfo.status = 1
        listpath.Add(pathinfo)
        pathinfo.path = "BBBBBBBB1"
        pathinfo.status = 1
        listpath.Add(pathinfo)
        pathinfo.path = "CCCCCCCC1"
        pathinfo.status = 1
        listpath.Add(pathinfo)
        pathinfo.path = "DDDDDDDD1"
        pathinfo.status = 1
        listpath.Add(pathinfo)
        pathinfo.path = "AAAAAAA2"
        pathinfo.status = 2
        listpath.Add(pathinfo)
        pathinfo.path = "BBBBBBBB2"
        pathinfo.status = 2
        listpath.Add(pathinfo)
        pathinfo.path = "CCCCCCCC2"
        pathinfo.status = 2
        listpath.Add(pathinfo)
        pathinfo.path = "DDDDDDDD2"
        pathinfo.status = 2
        listpath.Add(pathinfo)
    End Sub
    Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
        Dim myfont As New Font("arial", 12, FontStyle.Bold)
        Dim heightitem As Integer = 0

        For Each item In listpath
            If item.status = 0 Then
                e.Graphics.DrawString(item.path, myfont, Brushes.Red, 2, 2 + heightitem)
            End If
            If item.status = 1 Then
                e.Graphics.DrawString(item.path, myfont, Brushes.Yellow, 2, 2 + heightitem)
            End If
            If item.status = 2 Then
                e.Graphics.DrawString(item.path, myfont, Brushes.Green, 2, 2 + heightitem)
            End If
            heightitem += Convert.ToInt32(e.Graphics.MeasureString(item.path, myfont).Height * 1.25)
        Next

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ListBox1.DrawMode = DrawMode.OwnerDrawVariable
        GetPath()
    End Sub
End Class


le bug dès que je scroll tout est chamboulé
à moins que tu as fait autrement
0
Rejoignez-nous