RemoveChild

  • Thread starter Thread starter Meelis Lilbok
  • Start date Start date
M

Meelis Lilbok

Hi

What can next problem:

'Code
For Each oNode in oParent.ChildNodes
oParent.RemoveChild(oNode)
Next

Problem: Only first child node is removed!

Best regadrs;
Mex
 
Hi Mex,


You are modifying the collection you are enumerating, which is not a good
idea.

Is there something wrong with oParent.Clear()?


Robin
 
ehh of course, forgot about enum :))

solution is

'Remove child nodes
For i As Integer = oParent.ChildNodes.Count - 1 To 0 Step -1
oParent.RemoveChild(oParent.ChildNodes(i))
Next

Mex
 
Maybe a little tidier:


While oParent.ChildNodes.Count > 0
oParent.ChildNodes.RemoveAt (0)
End While


but I still prefer:

oParent.ChildNodes.Clear()
 
Back
Top