How to override remove method

How to override remove method

Old forum URL: forums.lhotka.net/forums/t/10998.aspx


vbbeta posted on Tuesday, December 20, 2011

Hi guys I have a problem while trying to override the remove method in a collection basically what I want it should do that the yo should call a remove method and remove the selected object from the list but this does not happen because it keeps on looping since the remove method was overridden

 

 

 

Here is my code 

 

Public overloads sun remove(I'd as integer) 

For each info as obj in me 

If obj.objid=Id 

Remove(obj)

Exit sub

End sub

 

But this doesn't work because it's causing a loop that doesn't stop any help on this 

JonnyBee replied on Tuesday, December 20, 2011

You must call Parent.Remove and not the overridden metod as a recursive call.

And you should also use a linq query or move item to a variable. You cannot remove an item inside a for-each loop.

vbbeta replied on Tuesday, December 20, 2011

I did try MyBase.Remove But it gives me the error "Invalid for root objects - use Delete instead"

 

so i tried MyBase.Items.Remove but it doesn't remove from the collection 

Copyright (c) Marimer LLC