Link to home
Start Free TrialLog in
Avatar of General_GSpot
General_GSpot

asked on

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?
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Are you sure that there are different file-dates in your directory ?
Avatar of General_GSpot
General_GSpot

ASKER

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?
Does it work if you use GetCreationTime function?
@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.
Just change this bit

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


to

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

ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@ark, your rank is true.
Glad I could help