ErocM
ErocM

Reputation: 4662

Cannot get date into listview column

I am trying to populate a listview with a file's name and date.

My code:

  Private Sub combobox_Coids_SelectedIndexChanged(sender As Object, e As EventArgs) Handles combobox_Coids.SelectedIndexChanged

    With ListView1
      .Items.Clear()
      .Clear()
      .View = View.Details
      .Columns.Add("Filename")
      .Columns.Add("Date")
    End With

    If File.Exists(sRpgEbillFile) Then
      ListView1.Items.Add(Path.GetFileName(sRpgEbillFile), File.GetCreationTime(sRpgEbillFile))
    End If

    Dim partfile As String = String.Format("{0}ebill\{1}\", sRpgDir, strCoid)
    'Dim filename As String = String.Format("{1}ebill.*", sRpgDir, strCoid)
    Dim filePaths As Linq.IOrderedEnumerable(Of IO.FileInfo) = New DirectoryInfo(partfile).GetFiles().OrderBy(Function(f As FileInfo) f.CreationTime)

    Dim qry = From files In filePaths
              Where files.CreationTime > DateTime.Now.AddDays(-30)
            Order By files.CreationTime Descending
    Select files

    Dim count As Integer = 0
    For Each fi As IO.FileInfo In qry
      If count > 20 Then Exit For
      ListView1.Items.Add(Path.GetFileName(fi.FullName), fi.CreationTime.ToShortDateString())
      count += 1
    Next

  End Sub

I am getting nothing in the date column and I cannot figure out why.

Anyone see what I am doing wrong?

Upvotes: 0

Views: 535

Answers (1)

Capellan
Capellan

Reputation: 700

Your CreationTime is going into the parameter for imageKey. You could do something like this:

ListView1.Items.Add(New ListViewItem(New String() {Path.GetFileName(fi.FullName), fi.CreationTime.ToShortTimeString()}))

The ListViewItem accepts a string array of subitems for your row data.

Upvotes: 1

Related Questions