我想在 ListView 上显示我的 FTP 服务器上的目录和文件。我是 ListViews 的新手,所以有人可以帮我开始吗?
代码:
Dim newSelected As TreeNode = e.Node
ListView1.Items.Clear()
Dim nodeDirInfo As DirectoryInfo = _
CType(newSelected.Tag, DirectoryInfo)
Dim subItems() As ListViewItem.ListViewSubItem
Dim item As ListViewItem = Nothing
Dim dir As DirectoryInfo
For Each dir In nodeDirInfo.GetDirectories()
item = New ListViewItem(dir.Name, 0)
subItems = New ListViewItem.ListViewSubItem() _
{New ListViewItem.ListViewSubItem(item, "Directory"), _
New ListViewItem.ListViewSubItem(item, _
dir.LastAccessTime.ToShortDateString())}
item.SubItems.AddRange(subItems)
ListView1.Items.Add(item)
Next dir
Dim file As FileInfo
For Each file In nodeDirInfo.GetFiles()
item = New ListViewItem(file.Name, 1)
subItems = New ListViewItem.ListViewSubItem() _
{New ListViewItem.ListViewSubItem(item, "File"), _
New ListViewItem.ListViewSubItem(item, _
file.LastAccessTime.ToShortDateString())}
item.SubItems.AddRange(subItems)
ListView1.Items.Add(item)
Next file