delete multiple TreeNodes

Heike

Well-known member
Joined
Jun 5, 2002
Messages
56
I have an ArrayList containing all selected TreeNodes in my TreeView. Now I want to delete them. How? I thought just using

For Each DummyNode In alNodes
Me.treDokumente.Nodes.Remove(DummyNode)
Next

would do it, but it doesnt. The first node is removed and then the error is something like "collection was modified; enumeration operation may not execute". Even after a alNodes.Reverse before doing it, the same error occured. Any suggestions?!
 
Since youre enumerating your own collection not the actual nodes in the treeview, Im wondering why this is happening. Have you tried using the Remove method of the nodes instead?

Code:
For Each DummyNode In alNodes
  DummyNode.Remove()
Next
 
Thanks, but that doesnt work either.

Im enumerationg my own collection because I had to create my own type because the base TreeView does not support multiple selection.
 
Try implementing a IEnumerator interface instead.

Code:
Dim ieNodes As System.Collections.IEnumerator = alNodes.GetEnumerator

While ieNodes.MoveNext
    Remove
End While
 
Back
Top