delete multiple TreeNodes

Heike

Regular
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 doesn't. 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 you're enumerating your own collection not the actual nodes in the treeview, I'm wondering why this is happening. Have you tried using the Remove method of the nodes instead?

Visual Basic:
For Each DummyNode In alNodes
  DummyNode.Remove()
Next
 
Thanks, but that doesn't work either.

I'm 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.

Visual Basic:
Dim ieNodes As System.Collections.IEnumerator = alNodes.GetEnumerator

While ieNodes.MoveNext
    'Remove
End While
 
Back
Top