Treeview 节点显示问题
代码如下:
Private Function TreeFiles(ByVal strPath As String, Optional ByVal strSearch As String = " ")
Dim treeFileDir As String
Dim i As Long
Dim lDirCount As Long
If strPath <> " " And Not strPath Is Nothing Then
If Microsoft.VisualBasic.Right(strPath, 1) <> "\ " Then strPath = strPath + "\ "
treeFileDir = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
While treeFileDir <> " "
If (GetAttr(strPath + treeFileDir) And vbDirectory) = vbDirectory Then 'find
If treeFileDir <> ". " And treeFileDir <> ".. " Then
ReDim Preserve treeFileDir1(lDirCount)
treeFileDir1(lDirCount) = treeFileDir 'save filename
lDirCount = lDirCount + 1
End If
Else
If strSearch = " " Then
TreeView1.Nodes.Add(New myTreeNode(strPath + treeFileDir))
ElseIf LCase(GetExtName(strPath + treeFileDir)) = LCase(GetExtName(strSearch)) Then
TreeView1.Nodes.Add(New myTreeNode(strPath + treeFileDir))
End If
End If
treeFileDir = Dir()
End While
End If
For i = 0 To lDirCount - 1
TreeView1.Nodes.Add(New myTreeNode(strPath & "\ " & treeFileDir1(i)))
Call TreeFiles(strPath + treeFileDir1(i), strSearch)
Next
End Function
Public Function GetExtName(ByVal strFileName As String) As String
Dim strTmp As String
Dim strByte As String
Dim i As Long
For i = Len(strFileName) To 1 Step -1
strByte = Mid(strFileName, i, 1)
If strByte <> ". " Then
strTmp = strByte + strTmp
Else
Exit For
End If
Next i
GetExtName = strTmp
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call TreeFiles( "C:\Documents and Settings\ ")
End Sub
这个只能把所有的目录文件夹(不管是子目录还是跟目录)都添加到跟节点下面了、
不会用这个空间、希望高手能给点支持、最好是详细点的(有参考例子的最好)
[解决办法]
我用的是 vs.net 2005 版本,My 新增的,你用的是不是.Net 2003 啊?