Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Resize the Control
Me.Size = New Size(500, 250)
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
'Creates a new listview with the following properties
Dim lv As New ListView
With lv
.Dock = DockStyle.Fill ' -----------------------|
.View = View.Details ' -------------------------|
.FullRowSelect = True ' ------------------------|
.GridLines = True ' ----------------------------|
' End of properties
Me.Controls.Add(lv)
'Creates listview columns
Dim col1, col2 As New ColumnHeader
col1.Text = "File Path"
col2.Text = "File Name"
.Columns.AddRange(New ColumnHeader() {col1, col2})
' and then resizing by half - 5
For Each col As ColumnHeader In .Columns
col.Width = (lv.Width / 2) - 5
Next
End With
' Now extracting the files
Dim path As String = "C:\Users\Aaron\Desktop\Slides" 'File Path
Dim dirInfo As New IO.DirectoryInfo(path)
Dim fileInfo As IO.FileInfo() = dirInfo.GetFiles()
'list the names of all files in the specified directory
For Each file As IO.FileInfo In fileInfo ' Goes through each file in this directory provided by "Path"
Dim item As New ListViewItem(file.FullName) ' [Step 1] Creates a new ListViewItem & Sets the first column (Indexed as 0) as the full file path of the file
item.SubItems.Add(file.Name) ' [Step 2] Now, creates a sub item of the same item that was intially created of the file name
lv.Items.Add(item) ' [Step 3] Finally, adding the item into the listview
Next ' and will now go to the next file and complete step 1 - 3 again until there are no more files to read
End Sub