views:

721

answers:

2

I have a collection object that implements IList. Inside the collection I have used a List to collect the items. Inside the PropertyGrid (at runtime), it binds properly and the Collection Editor opens. I can edit, and I can add items properly and I can catch these methods when they are used in the collection class.

However, if you try to remove any items, they get removed from the collection, but neither IList.Remove or IList.RemoveAt are seemingly used from my Collection. The items deleted are also meant to be deleted from a database, behaviour I implement in the Remove methods.

I also removed all the logic from the remove methods and left them with throw new NotImplmented(), and these don't get fired at all!

I also have an implemented by own CollectionEditor, but still can't see a way to hook into my objects.

So, where should I be looking to find the relevant methods? do I need to change the behaviour of my items as well?

A: 

The Collection Editor doesn't use Remove or RemoveAt. Instead, when the user presses the OK button, it calls the IList.Clear method and then calls IList.Add to add all the items the collection will contain. Not that it works with the non-generic version of IList.

Vojislav Stojkovic
A: 

Well, Rats!

Inside my CollectionEditor is there any way to get hold of the actual collection? I think I'll get the collection, and then compare it once OK has been pressed, and delete the records from there.

failing that, dust off the matrix screen saver, dig out a good book and tell everyone it's compiling.

Paul Lawrence
You have two options that I can think of. The first option is to do what you said, compare the new collection with the old collection (perhaps inside CollectionEditor.SetItems) and do whatever it is you want to do there. This options is easier to implement, but might be costly to run.
Vojislav Stojkovic
The second option is to implement not only your own CollectionEditor but also the CollectionEditorForm. Make the form keep track of what user added and removed (as a list of commands) and, when the user presses OK, process that list of commands.
Vojislav Stojkovic