Populate Treeview with folders and files
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
I'm trying to make an application that will let the user select a usb drive and then load all the directories/subdirectories/files into the treeview (I want it to only show the image files).
Anyone have a base code they can help me with?
Anyone have a base code they can help me with?
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that
I have a tutorial at http://smashapps.net/tutorials.html
In the tutorial code you can just change the path and the files that are displayed, the tutorial lists mp3 files, if you need more help pm me because I have an application of mine that does the same thing you need
In the tutorial code you can just change the path and the files that are displayed, the tutorial lists mp3 files, if you need more help pm me because I have an application of mine that does the same thing you need
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
Are you sure you want the files listed in the treeview? It would be better with files in a listview, and folders in the treeview. And do you want icons to be displayed too next to the items?
Code: Select all
'At top of code file'
Imports System.IO
'Public class Form1 blabla'
Private Sub Form_Load() Handles Me.Load
For Each d As DriveInfo In DriveInfo.GetDrives
If Not d.IsReady Then Continue For
Dim n As New TreeNode(d.RootDirectory.Name)
n.Tag = d.RootDirectory
If d.RootDirectory.GetDirectories().Count > 0 Or GetFiles(d.RootDirectory).Count > 0 Then
n.Nodes.Add("*")
End If
TreeView1.Nodes.Add(n)
Next
End Sub
Private Sub TreeView1_BeforeExpand(sender As System.Object, e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
If e.Node.FirstNode.Text = "*" Then
e.Node.Nodes.Clear()
Dim dir As DirectoryInfo = DirectCast(e.Node.Tag, DirectoryInfo)
For Each d As DirectoryInfo In dir.GetDirectories()
If d.Attributes And FileAttributes.Hidden Then Continue For
Dim n As New TreeNode(d.Name)
Try
If d.GetDirectories().Count > 0 Or GetFiles(d).Count > 0 Then
n.Nodes.Add("*")
End If
Catch
End Try
n.Tag = d
e.Node.Nodes.Add(n)
Next
Try
For Each f As FileInfo In GetFiles(dir)
Dim n As New TreeNode(f.Name)
n.Tag = f
e.Node.Nodes.Add(n)
Next
Catch
End Try
End If
End Sub
Private Function GetFiles(Directory As DirectoryInfo) As FileInfo()
Dim l As New List(Of FileInfo)
For Each ext As String In Extensions
For Each f As FileInfo In Directory.GetFiles(ext)
l.Add(f)
Next
Next
Return l.ToArray
End Function
Private ReadOnly Extensions As String() = New String() {"*.bmp", "*.jpg", "*.jpeg", "*.png", "*.tiff", "*.tif", "*.gif"}
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Oh i must of misread that, my tutorial is for a Listview, sorry about that
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023