|
-
Jun 1st, 2009, 03:57 PM
#1
Thread Starter
New Member
[RESOLVED] WPF TreeView Events
im trying to create an Explorer like control useing the TreeView control and the code below, but
it looks like the Expanded event of the root node is raised everytime i remove the child nodes from the currently selected node, i need to remove the child nodes of the currently expanded node so i can refresh the list of folders
is there a way i can prevent it from doing this, or is there a better Explorer like control i can use?
Code:
Private Sub windowMain_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
For Each Drive As IO.DriveInfo In IO.DriveInfo.GetDrives
Dim Item As New TreeViewItem
Item.Header = Drive.Name
Item.Tag = Drive.Name
AddHandler Item.Expanded, AddressOf treeExplorer_Expanded
treeExplorer.Items.Add(Item)
Next
End Sub
Private Sub treeExplorer_Expanded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim ExpandedItem As TreeViewItem = DirectCast(sender, TreeViewItem)
Dim Path As String = DirectCast(ExpandedItem.Tag, String)
Debug.WriteLine(Path)
ExpandedItem.Items.Clear() ' i think this causes the expanded event of the root node to be raised
For Each Folder As String In IO.Directory.GetDirectories(Path)
Dim Item As New TreeViewItem
Item.Header = Folder.Substring(Folder.LastIndexOf("\") + 1)
Item.Tag = Folder
AddHandler Item.Expanded, AddressOf treeExplorer_Expanded
ExpandedItem.Items.Add(Item)
Next
End Sub
Last edited by ambiguousPanda; Jun 10th, 2009 at 05:38 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|