Advertisement
smashapps

Filling listView with specified files

May 21st, 2011
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim Dir As New DirectoryInfo(Application.StartupPath & "/Data/")
  7.         FillListView(Dir)
  8.     End Sub
  9.  
  10.     Private Sub FillListView(ByVal Folder As DirectoryInfo)
  11.         Static ImageList As New ImageList With {.ColorDepth = ColorDepth.Depth32Bit, .ImageSize = New Size(32, 32)}
  12.         Static ImgIndex As Integer = 0
  13.  
  14.         ListView1.LargeImageList = ImageList
  15.         ListView1.View = View.Tile
  16.  
  17.         For Each F As FileInfo In Folder.GetFiles("*.txt")
  18.             ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
  19.             ListView1.Items.Add(F.Name, ImgIndex).Tag = F
  20.             ImgIndex += 1
  21.         Next
  22.  
  23.         For Each Dir As DirectoryInfo In Folder.GetDirectories
  24.             FillListView(Dir)
  25.         Next
  26.     End Sub
  27. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement