我正在尝试使用文件的名称和日期填充列表视图。
我的代码:
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
我在日期栏中什么都没得到,我无法弄明白为什么。
任何人都能看到我做错了什么?
答案 0 :(得分:1)
您的CreationTime将进入imageKey的参数。你可以这样做:
ListView1.Items.Add(New ListViewItem(New String() {Path.GetFileName(fi.FullName), fi.CreationTime.ToShortTimeString()}))
ListViewItem接受行数据的子项的字符串数组。