IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

favoris dans treeview


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut favoris dans treeview
    bonjour a tous

    j'ai voulu afficher dans un treeview les favoris par défault de IE
    mais sa marche qu'a moitié il m'affiche juste les répertoire mais pas leur contenu et en + je suis pas sur que quand je clique dessus sa se lance sur mon webbrowser. avez vous une idée?
    voici mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Private Sub Form6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            LoadFavorites()
     
        End Sub
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    Private Sub LoadFavorites()
            Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
            TreeView1.BeginUpdate()
            TreeView1.Nodes.Clear()
            LoadFolders(New System.IO.DirectoryInfo(Path), Nothing)
     
            LoadPath(Path, Nothing)
     
     
            TreeView1.EndUpdate()
        End Sub
        Private Sub LoadFolders(ByVal dirInfo As System.IO.DirectoryInfo, ByVal currentNode As TreeNode)
     
            Dim objNode As System.Windows.Forms.TreeNode
     
            Dim objDir As System.IO.DirectoryInfo
     
            For Each objDir In dirInfo.GetDirectories()
                If currentNode Is Nothing Then
                    objNode = TreeView1.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                    objNode.Tag = String.Empty
     
                Else
                    objNode = currentNode.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                    objNode.Tag = String.Empty
     
                End If
     
                objNode.Tag = objDir.FullName
     
                If objDir.GetDirectories().Length = 0 Then
     
                End If
            Next objDir
        End Sub
        Private Sub LoadPath(ByVal strPath As String, ByVal currentNode As TreeNode)
     
            Dim oNode As TreeNode
     
            Dim name As String
            Dim objDir As New System.IO.DirectoryInfo(strPath)
            Dim SmallIco As IntPtr
            Dim shinfo As SHFILEINFO
            shinfo = New SHFILEINFO
     
            Dim objFile As System.IO.FileInfo
            For Each objFile In objDir.GetFiles("*.url")
                oNode = New TreeNode
     
                shinfo.szDisplayName = New String(Chr(0), 260)
                shinfo.szTypeName = New String(Chr(0), 80)
     
                SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
                            Marshal.SizeOf(shinfo), _
                            SHGFI_ICON Or SHGFI_SMALLICON)
     
                name = Path.GetFileNameWithoutExtension(objFile.Name)
                Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
                TreeView1.ImageList.Images.Add(name, oIcon.ToBitmap)
                oNode.Text = name
                oNode.Tag = objFile.FullName
                oNode.ImageKey = name
                oNode.SelectedImageKey = name
                If currentNode Is Nothing Then
                    TreeView1.Nodes.Add(oNode)
                End If
            Next objFile
        End Sub

  2. #2
    Modérateur

    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2007
    Messages
    1 996
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2007
    Messages : 1 996
    Par défaut
    Il est normal que tu ne récupères que les répertoires puisque tu ne parcours pas tes favoris de façon récursive.
    GetDirectories ne te renvoie donc que les répertoires de premier niveau.

  3. #3
    Invité
    Invité(e)
    Par défaut
    j'ai oublier quelque chose alors

  4. #4
    Membre éclairé Avatar de lukeni2
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2008
    Messages
    92
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Finance

    Informations forums :
    Inscription : Février 2008
    Messages : 92
    Par défaut
    tu aura besoin d'effectuer un balayage recursif de ton dossier. ci-dessous un petit exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Private Sub CreerListeDossier(ByVal dossierSource As DirectoryInfo)
    listeDossier.add(dossierSource.FullName)
    For Each di As DirectoryInfo In dossierSource .GetDirectories()
                CreerListeDossier(di)
    Next
    End Sub

  5. #5
    Invité
    Invité(e)
    Par défaut
    j'ai un petit peu modifié le code mais sa ne marche toujours pas
    je vois toujours les dossier mais pas leur contenu

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    Private Sub LoadFavorites()
            Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
            TreeView1.BeginUpdate()
            TreeView1.Nodes.Clear()
            LoadFolders(New System.IO.DirectoryInfo(Path), Nothing)
     
            LoadPath(Path, Nothing)
            LoadLinkFolders(New System.IO.DirectoryInfo(Path & "\Links\"))
            LoadLinksPath(Path & "\Links\")
     
            TreeView1.EndUpdate()
        End Sub
        Private Sub LoadFolders(ByVal dirInfo As System.IO.DirectoryInfo, ByVal currentNode As TreeNode)
            Dim objNode As System.Windows.Forms.TreeNode
            Dim objDir As System.IO.DirectoryInfo
     
            For Each objDir In dirInfo.GetDirectories()
     
                If currentNode Is Nothing Then
                    objNode = TreeView1.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                    objNode.Tag = String.Empty
     
                Else
                    objNode = currentNode.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                    objNode.Tag = String.Empty
                End If
                objNode.Tag = objDir.FullName
                If objDir.GetDirectories().Length = 0 Then
                    LoadPath(objDir.FullName, objNode)
                Else
                    LoadFolders(objDir, objNode)
                    LoadPath(objDir.FullName, objNode)
                End If
            Next objDir
     
        End Sub
        Private Sub LoadPath(ByVal strPath As String, ByVal currentNode As TreeNode)
     
            Dim oNode As TreeNode
            Dim name As String
            Dim objDir As New System.IO.DirectoryInfo(strPath)
            Dim SmallIco As IntPtr
            Dim shinfo As SHFILEINFO
            shinfo = New SHFILEINFO
     
            Dim objFile As System.IO.FileInfo
            For Each objFile In objDir.GetFiles("*.url")
                oNode = New TreeNode
     
                shinfo.szDisplayName = New String(Chr(0), 260)
                shinfo.szTypeName = New String(Chr(0), 80)
     
                SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
                            Marshal.SizeOf(shinfo), _
                            SHGFI_ICON Or SHGFI_SMALLICON)
     
                name = Path.GetFileNameWithoutExtension(objFile.Name)
                Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
                TreeView1.ImageList.Images.Add(name, oIcon.ToBitmap)
                oNode.Text = name
                oNode.Tag = objFile.FullName
                oNode.ImageKey = name
                oNode.SelectedImageKey = name
                If currentNode Is Nothing Then
                    TreeView1.Nodes.Add(oNode)
                End If
            Next objFile
        End Sub
        Private Sub LoadLinkFolders(ByVal dirInfo As System.IO.DirectoryInfo)
            Dim objDir As System.IO.DirectoryInfo
     
            For Each objDir In dirInfo.GetDirectories()
     
     
                If objDir.GetDirectories().Length = 0 Then
     
                    LoadLinksPath(objDir.FullName)
                Else
     
                    LoadLinkFolders(objDir)
                    LoadLinksPath(objDir.FullName)
                End If
            Next objDir
        End Sub
        Private Sub LoadLinksPath(ByVal strPath As String)
     
            Dim name As String
            Dim objDir As New System.IO.DirectoryInfo(strPath)
            Dim SmallIco As IntPtr
            Dim shinfo As SHFILEINFO
            shinfo = New SHFILEINFO
     
            Dim objFile As System.IO.FileInfo
            For Each objFile In objDir.GetFiles("*.url")
     
     
                shinfo.szDisplayName = New String(Chr(0), 260)
                shinfo.szTypeName = New String(Chr(0), 80)
     
                SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
                            Marshal.SizeOf(shinfo), _
                            SHGFI_ICON Or SHGFI_SMALLICON)
     
                name = Path.GetFileNameWithoutExtension(objFile.Name)
                Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
     
            Next objFile
        End Sub

Discussions similaires

  1. [Débutant] Favoris dans treeview
    Par Invité dans le forum VB.NET
    Réponses: 7
    Dernier message: 19/08/2011, 17h00
  2. dimension partie favoris dans IE
    Par hellosct1 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 04/10/2005, 11h23
  3. image de fond dans treeview
    Par chancourt dans le forum Composants VCL
    Réponses: 4
    Dernier message: 17/08/2005, 17h11
  4. menu contextuel dans treeview
    Par GAGNON dans le forum IHM
    Réponses: 6
    Dernier message: 08/04/2005, 19h11
  5. icon dans treeview ou listview
    Par Sebinou dans le forum C++Builder
    Réponses: 12
    Dernier message: 31/03/2004, 01h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo