02-26-2012, 10:51 AM
Well, this doesn't work because your code is inside of the SelectedIndexChanged method. This means that you would have to essentially change what is selected in the listbox in order to get the files to appear. However, you cannot change your selection because there is nothing to select!
Try moving your code around like this:
Try moving your code around like this:
Code:
Public Class Form3
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim directory = "C:\PIF"
Dim files() As System.IO.FileInfo
Dim dirinfo As New System.IO.DirectoryInfo(directory)
files = dirinfo.GetFiles("*", IO.SearchOption.AllDirectories)
For Each file In files
ListBox1.Items.Add(file)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
End Class