Using listview as file/ folders explorer

LabRat picture LabRat · Sep 2, 2015 · Viewed 9.1k times · Source

I'm new to using listview to display icons. I have a few questions remaining...

I am currently using the following code as example. This code works fine, I have questions though

  1. How do I get rid of the path name and only keep the file / folder name?
  2. How do I also list folders alongside my files?
  3. How can I click open these icons?

-

For Each File In System.IO.Directory.GetFiles("C:\")
    Dim icons As Icon = Icon.ExtractAssociatedIcon(File)
    ListView1.Items.Add(File.ToString, ImageList1.Images.Count - 1)
    ImageList1.Images.Add(icons)
    ListView1.Items.Add(File.ToString, ImageList1.Images.Count)
Next

Answer

Chris picture Chris · Sep 2, 2015

You may have a look into using treeview... hope that helps

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim x As Integer
    For x = 0 To My.Computer.FileSystem.Drives.Count - 1
        If My.Computer.FileSystem.Drives(x).IsReady = True Then
            TreeView1.Nodes.Add(My.Computer.FileSystem.Drives(x).Name, My.Computer.FileSystem.Drives(x).Name)
            TreeView1.Nodes(My.Computer.FileSystem.Drives(x).Name).Tag = My.Computer.FileSystem.Drives(x).Name
            For Each SubDirectory As String In My.Computer.FileSystem.GetDirectories(My.Computer.FileSystem.Drives(x).Name)
                TreeView1.Nodes(x).Nodes.Add(SubDirectory, Mid(SubDirectory, 4))
                TreeView1.Nodes(x).Nodes(SubDirectory).Tag = SubDirectory
            Next
        End If
    Next
End Sub