05-21-2014 07:14 AM
Hi
I want to remove all my PointAnnotations in a graph. I have tried the code below but it doesn't work. Is there som other way?
Thanks
/Axel
For i = 0 To sg.Children.Count - 1
If sg.Children(i).GetType = GetType(PointAnnotation) Then
sg.Children.Remove(i)
EndIf
Next
Solved! Go to Solution.
05-21-2014 10:17 AM
There are two issues with the code as written:
Remove method on ObjectCollection instead of the RemoveAt method (i.e. it is trying to remove the object i, not the element at index i).i, all the later elements in the collection effectively shift down one, but the For loop still increments i before checking the next element, skipping adjacent values.When removing elements, it is best to iterate backwards over the collection to avoid index mis-alignment:
For i = sg.Children.Count - 1 To 0 Step -1
If sg.Children(i).GetType = GetType(PointAnnotation) Then
sg.Children.RemoveAt(i)
End If
Next
05-22-2014 12:47 AM
Thanks ![]()
/Axel