For ERC base.RemoveItem(index) is giving Error "Invalid for root objects - use Delete instead"

For ERC base.RemoveItem(index) is giving Error "Invalid for root objects - use Delete instead"

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


Raju posted on Tuesday, August 07, 2007

Hi ,

I bind ERC (Editable Root Collection) object to DataGridView.

When I want to Delete a row in DataGridView, internally the "RemoveItem(..)" is called (I have given the syntax for that below).

Inside the RemoveItem, when the base.RemoveItem(index) is executed, I get the following error..

1) Error  --  System.NotSupportedException "Invalid for root objects - use Delete instead".

2) Code for "RemoveItem"

               protected override void RemoveItem(int index)

               {

                        this[index].Delete();

                        base.RemoveItem(index);

                }

3) Question - For a Root object, if I have to remove it from the collection, what is the approach should I follow?. Because I want the Removed item to be in the DeletedList in my ERC, so that I can use it for NLevel UNDO.

Thanks in advance

Raju 

RockfordLhotka replied on Tuesday, August 07, 2007

You can't have an ERC contain an ERO (editable root object). An ERC contains ECOs (editable child objects).

If you want a collection that contains EROs, you'll have to use EditableRootListBase - though that has some different behaviors than ERC, so read up on it in the CSLA .NET Version 2.1 Handbook so you know what to expect. Given your #3 question, it sounds like ERLB won't work though.

Or you'll need to create your own collection base class, sort of like BusinessListBase, but also sort of like ERLB.

Or you'll need to change your EROs to be ECOs so they fit into the supported model.

Copyright (c) Marimer LLC