Here's my code that adds items (filenames) and subitems (file dates and size) to a listview control. The problem is that some of the subitems (file dates) don't get added (see attached image). I've removed my try, end try statements and no error. I step through the code and still no error. I'm totally Stuck. Can anyone help me?
Visual Basic:
Dim BrowseFolder As New FolderBrowserDialog
BrowseFolder.ShowNewFolderButton = False
BrowseFolder.Description = "Select folder for LEFT list."
BrowseFolder.ShowDialog()
cmboLeft.Items.Add(BrowseFolder.SelectedPath)
cmboLeft.Text = BrowseFolder.SelectedPath
cmboLeft.Refresh()
lvwLeftList.Items.Clear()
Dim file As String, files As String()
Dim Fdate As String = ""
files = System.IO.Directory.GetFiles(BrowseFolder.SelectedPath)
Dim ex As Integer = 0
For Each file In files
Dim SlashLen As Integer = file.LastIndexOf("\") + 1
Dim FileLen As Integer
FileLen = Len(file)
Dim RemainLen As Integer
RemainLen = FileLen - SlashLen
Dim StrFileOnly As String
StrFileOnly = file.Substring(SlashLen, RemainLen)
Dim information As System.IO.FileInfo
information = My.Computer.FileSystem.GetFileInfo(file)
Dim fileDate As String
fileDate = information.LastWriteTime
Dim fileSize As Long
fileSize = My.Computer.FileSystem.GetFileInfo(file).Length
If fileSize < 1024 Then
fileSize = 1
Else
fileSize = fileSize / 1024
End If
lvwLeftList.Items.Add(StrFileOnly, 0) ' (cmboLeft.Items.Count - 1))
lvwLeftList.Items(ex).SubItems.Add(fileDate)
lvwLeftList.Items(ex).SubItems.Add(fileSize & " KB")
ex = ex + 1
StatusStrip1.Refresh()
lvwLeftList.Refresh()
ToolStripStatusLeftShown.Text = "Files: " & lvwLeftList.Items.Count
Next