|
本帖最后由 todaynew 于 2012-4-3 21:31 编辑
第七节:
1、拖一个ListView控件到SplitContainer控件的右侧区域中,对ListView控件的属性进行一些设置。
2、测试效果。
第八节:
1、写一个子程序用于在点击TreeView节点时,在ListView中呈现该节点对应文件夹下的子文件夹和文件。
Private Sub FilterListView(mynode As TreeNode)
....
End Sub
2、先写一段呈现子文件夹的代码:
Private Sub FilterListView(mynode As TreeNode)
ListView1.Items.Clear() '清空ListView
Dim dir As DirectoryInfo = New DirectoryInfo(mynode.Tag.ToString)
Dim item As ListViewItem = Nothing
Dim subitem As ListViewItem.ListViewSubItem() = Nothing
For Each subdir As DirectoryInfo In dir.GetDirectories
item = New ListViewItem(subdir.Name, 0)
Dim subitem As ListViewItem.ListViewSubItem() = Nothing
For Each subdir As DirectoryInfo In dir.GetDirectories
item = New ListViewItem(subdir.Name, 0)
subitem = New ListViewItem.ListViewSubItem() _
{New ListViewItem.ListViewSubItem(item, "文件夹"), _
New ListViewItem.ListViewSubItem(item, subdir.LastWriteTime.ToString)}
item.SubItems.AddRange(subitem)
ListView1.Items.Add(item)
Next
Next
End Sub
3、接着写一段呈现文件的代码:
Private Sub FilterListView(mynode As TreeNode)
ListView1.Items.Clear() '清空ListView
Dim dir As DirectoryInfo = New DirectoryInfo(mynode.Tag.ToString)
Dim item As ListViewItem = Nothing
Dim subitem As ListViewItem.ListViewSubItem() = Nothing
For Each subdir As DirectoryInfo In dir.GetDirectories
item = New ListViewItem(subdir.Name, 0)
Dim subitem As ListViewItem.ListViewSubItem() = Nothing
For Each subdir As DirectoryInfo In dir.GetDirectories
item = New ListViewItem(subdir.Name, 0)
subitem = New ListViewItem.ListViewSubItem() _
{New ListViewItem.ListViewSubItem(item, "文件夹"), _
New ListViewItem.ListViewSubItem(item, subdir.LastWriteTime.ToString)}
item.SubItems.AddRange(subitem)
ListView1.Items.Add(item)
Next
For Each File As FileInfo In dir.GetFiles
item = New ListViewItem(subdir.Name, 0)
subitem = New ListViewItem.ListViewSubItem() _
{New ListViewItem.ListViewSubItem(item, "文件夹"), _
New ListViewItem.ListViewSubItem(item, subdir.LastWriteTime.ToString)}
item.SubItems.AddRange(subitem)
ListView1.Items.Add(item)
Next
Next
End Sub
4、在TreeView1_NodeMouseClick中调用FilterListView。上述代码测试时会报错,原因是有些系统文件夹和文件需要权限,因此需要加上If和Try语句排除错误。
5、测试效果。
第二课示例文件:
上一课 下一课 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|