可以用TreeView(Microsoft Commom Control里的),也可以用API,但是微软似乎没有提供comclt32.dll里的函数声明。
解决方案 »
- 用vbscript写的代码怎么才能在vb里使用?(关于WMI)
- 新手急求:如何从程序中跳出来
- 大家快看这句导入SQL语句有什么问题?
- Datagrid控件的数据源能不能设为ACCESS数据库连接打开的表?
- 关于数据保存
- 作完SQL SERVER数据庫程序怎么把数据庫配置到别一台机子上!!!
- vb打包问题求教
- excel调用宏
- 三维命令按钮SSCommand的ocx文件是那一个,或者说是components中的那一项?
- 请问哪位高手知道,在数据窗体向导中,以绑定类型为ADO,窗体布局为网格生成的窗体中,最下边的那4个按钮上的图片是存入在硬盘上的何处啊?我想将这几个图型放到工具栏的按钮可以吗?
- 那位老兄能不能贴一个VB调用VC写的DLL的实例(字符串的传进传出)
- 菜鸟求助~~~
Dim oNode As New System.Windows.Forms.TreeNode()
Dim rootDir As String
Try
oNode.ImageIndex = 0
oNode.SelectedImageIndex = 0
oNode.Text = "我的电脑"
TreeView1.Nodes.Add(oNode)
Dim xx, i
For Each rootDir In Directory.GetLogicalDrives
Dim subNode As New System.Windows.Forms.TreeNode()
xx = Split(rootDir, "\")
subNode.Text = xx(0)
oNode.Nodes.Insert(i, subNode)
oNode.Nodes.Item(i).Nodes.Add("")
i = i + 1
Next
Catch ex As Exception
MsgBox("Cannot create initial node:" & ex.ToString)
End
End Try
End Sub
Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
If e.Node.ImageIndex = 2 Then Exit Sub Try
If e.Node.GetNodeCount(False) = 1 And e.Node.Nodes(0).Text = "" Then
e.Node.Nodes(0).Remove()
EnumerateChildren(e.Node)
End If
Catch ex As Exception
MsgBox("Unable to expand " & e.Node.FullPath & ":" & ex.ToString)
End Try If e.Node.GetNodeCount(False) > 0 Then
e.Node.ImageIndex = 1
e.Node.SelectedImageIndex = 1
End If End Sub Private Sub EnumerateChildren(ByVal oParent As System.Windows.Forms.TreeNode) Dim xx As String = oParent.FullPath
xx = Replace(xx, "我的电脑\", "")
Dim oFS As New DirectoryInfo(xx & "\")
Dim oDir As DirectoryInfo
Dim oFile As FileInfo Try
For Each oDir In oFS.GetDirectories()
Dim oNode As New System.Windows.Forms.TreeNode()
oNode.Text = oDir.Name
oNode.ImageIndex = 0
oNode.SelectedImageIndex = 0
oParent.Nodes.Add(oNode)
oNode.Nodes.Add("")
Next
Catch ex As Exception
MsgBox("Cannot list folders of " & oParent.FullPath & ":" & ex.ToString)
End Try Try
For Each oFile In oFS.GetFiles()
Dim oNode As New System.Windows.Forms.TreeNode()
oNode.Text = oFile.Name & " (" & oFile.Length & " bytes)"
oNode.ImageIndex = 2
oNode.SelectedImageIndex = 2
oParent.Nodes.Add(oNode)
Next
Catch ex As Exception
MsgBox("Cannot list files in " & oParent.FullPath & ":" & ex.ToString)
End Try End Sub Private Sub TreeView1_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeCollapse
e.Node.ImageIndex = 0
e.Node.SelectedImageIndex = 0
End Sub