lkelsen
07-15-2015, 05:32 PM
Hi team,
I have a TreeView which displays a windows folder directory, its sub-folders and files as nodes.
When I click on any node which represents a folder it will display the contents of that folder in a ListBox adjacent to the TreeView, it also displays the dot and dotdot which are the two representatives of the current folder and parent folder in windows. How do I exclude these two items from my ListBox?
In the past I have had the following code in the function:
For i = 1 To 3
Me.lstTV.RemoveItem (0)
Next i
This approach causes errors depending on certain events which occur in my interface and also to me seems messy.
This is the code that adds each directory item to the ListBox when a node is clicked on, using he NodeClick function:
Private Sub tvProjects_NodeClick(ByVal Node As MSComctlLib.Node)
Dim lstStrucTV As String, Arr As Variant, SelectedNode As MSComctlLib.Node, s As String, sPath As String, sPath2 As String, i As Integer
lstTV.Clear
Range("Q5").Clear
Set SelectedNode = frmProjTree.tvProjects.SelectedItem
With SelectedNode
s = .Text & vbCrLf
If Len(.Tag) > 0 Then
Arr = Split(.Tag, vbCrLf)
sPath = Arr(LBound(Arr) + 1) & "\"
sPath2 = Arr(LBound(Arr) + 1)
Else
End If
End With
If GetAttr(sPath2) And vbDirectory Then
'--sPath's are folders
lstStrucTV = dir(sPath & "*", vbDirectory)
'--populate the second level listbox with second level folder list
While lstStrucTV <> ""
lstTV.AddItem lstStrucTV
lstStrucTV = dir
Range("Q4").Clear
Range("Q3").Value = sPath
txtPath.Value = sPath
Wend
Else
Range("Q3").Clear
Range("Q4").Value = sPath2
txtPath.Value = sPath2
GoTo Quit
End If
If frmProjTree.tvProjects.SelectedItem.Children = 0 Then
GoTo Quit
End If
Quit:
End Sub
I have a TreeView which displays a windows folder directory, its sub-folders and files as nodes.
When I click on any node which represents a folder it will display the contents of that folder in a ListBox adjacent to the TreeView, it also displays the dot and dotdot which are the two representatives of the current folder and parent folder in windows. How do I exclude these two items from my ListBox?
In the past I have had the following code in the function:
For i = 1 To 3
Me.lstTV.RemoveItem (0)
Next i
This approach causes errors depending on certain events which occur in my interface and also to me seems messy.
This is the code that adds each directory item to the ListBox when a node is clicked on, using he NodeClick function:
Private Sub tvProjects_NodeClick(ByVal Node As MSComctlLib.Node)
Dim lstStrucTV As String, Arr As Variant, SelectedNode As MSComctlLib.Node, s As String, sPath As String, sPath2 As String, i As Integer
lstTV.Clear
Range("Q5").Clear
Set SelectedNode = frmProjTree.tvProjects.SelectedItem
With SelectedNode
s = .Text & vbCrLf
If Len(.Tag) > 0 Then
Arr = Split(.Tag, vbCrLf)
sPath = Arr(LBound(Arr) + 1) & "\"
sPath2 = Arr(LBound(Arr) + 1)
Else
End If
End With
If GetAttr(sPath2) And vbDirectory Then
'--sPath's are folders
lstStrucTV = dir(sPath & "*", vbDirectory)
'--populate the second level listbox with second level folder list
While lstStrucTV <> ""
lstTV.AddItem lstStrucTV
lstStrucTV = dir
Range("Q4").Clear
Range("Q3").Value = sPath
txtPath.Value = sPath
Wend
Else
Range("Q3").Clear
Range("Q4").Value = sPath2
txtPath.Value = sPath2
GoTo Quit
End If
If frmProjTree.tvProjects.SelectedItem.Children = 0 Then
GoTo Quit
End If
Quit:
End Sub