Missing dates on Listview

here is my code:
Private Sub treeview1_afterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

        Dim subitemindex As Integer
        Dim datemod As String

        If TreeView1.SelectedNode.Nodes.Count = 1 AndAlso TreeView1.SelectedNode.Nodes(0).Text = "Loading..." Then
            TreeView1.SelectedNode.Nodes.Clear()
            AddAllFolders(TreeView1.SelectedNode, CStr(TreeView1.SelectedNode.Tag))
        End If
        ListView1.Items.Clear()
        Dim folder As String = CStr(TreeView1.SelectedNode.Tag)

        If Not folder Is Nothing AndAlso IO.Directory.Exists(folder) Then
            Try
                For Each File As String In IO.Directory.GetFiles(folder)
                    datemod = IO.File.GetLastWriteTime(File).ToString()
                    ListView1.Items.Add(File.Substring(File.LastIndexOf("\"c) + 1), File.ToString())
                    ListView1.Items(subitemindex).SubItems.Add(datemod.ToString())
                Next
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If

    End Sub

Open in new window


Don't know what I'm missing, but I can only see the date on the first file in my listview, i'm certain it's a + 1 somewhere, just couldn't see it.

Anyone help?
LVL 1
General_GSpotAsked:
Who is Participating?
 
ArkCommented:
Since you don't increase subitemindes
ListView1.Items(subitemindex).SubItems.Add(datemod.ToString())
means
ListView1.Items(0).SubItems.Add(datemod.ToString())

You can use
ListView1.Items.Add(File.Substring(File.LastIndexOf("\"c) + 1), File.ToString()).SubItems.Add(datemod.ToString())
0
 
DhaestCommented:
Are you sure that there are different file-dates in your directory ?
0
 
General_GSpotAuthor Commented:
I know right, well, it happens now on 2 different directories. I may not have a large enough sample size, but each of the two directories have about 13 messages in them, yet only the first in each shows a date.

So are you saying the code is correct?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CodeCruiserCommented:
Does it work if you use GetCreationTime function?
0
 
General_GSpotAuthor Commented:
@CodeCruiser,

Honestly, this is my third week coding, trying to move from just PC support to a bit more and haven't had time to study/practice that much. Having trouble getting functions in... can you provide an example?

Thanks.
0
 
CodeCruiserCommented:
Just change this bit

datemod = IO.File.GetLastWriteTime(File).ToString()


to

datemod = IO.File.GetCreationTime(File).ToString()
0
 
General_GSpotAuthor Commented:
Same deal, I'll just try to get a larger sample size.

0
 
General_GSpotAuthor Commented:
@ark, your rank is true.
0
 
ArkCommented:
Glad I could help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.