PDA

Click to See Complete Forum and Search --> : [RESOLVED] WPF TreeView Events


ambiguousPanda
Jun 1st, 2009, 03:57 PM
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?




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

ambiguousPanda
Jun 2nd, 2009, 09:29 AM
is there a way i can stop the expanded event on the root node whne i delete the currently selected node ?

there used to be a TreeView.BeginUpdate and TreeView.EndUpdate, is there an equivalent function in wpf ?

ambiguousPanda
Jun 4th, 2009, 12:18 PM
boobies

ambiguousPanda
Jun 10th, 2009, 05:36 AM
solved it



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()

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

e.Handled = True ' this stops it from bubbling up to the root node

End Sub



BOOBIEWS