Remove from collection

Thread is closed for posting
2 posts, 0 answers
  1. Robert Lautenbach
    Robert Lautenbach avatar
    18 posts
    Member since:
    Dec 2009

    Posted 24 Jun 2010 Link to this post

    I'm using a reverse mapping on a project. I have a class that exposes a collection of another class type. When I use .remove(objectInstance) on the collection property I am able to remove from the working collection, but the change does not persist to the database.

    To go a little deeper, I have two rad list boxes. I'm adding new selections and deleting unselected elements on save.

    My underlying code uses the parent collection property to add new elements:

    And .Remove() to remove unselected elements:

    After looping through I call:

    The newly added object linkages save. But the removed linkages do not delete. The only way I can get it to work is to delete the child object via the scope:

    Since I'm checking my children collection for object existence repeatedly, if I only delete via scopeInstance.Remove(..) and not parentObject.Children.Remove(..) I get an error about attempting to read/write elements marked for deletion.

    Is there another way to go about persisting .Remove() calls for a child collection property?
  2. Petko_I
    Petko_I avatar
    184 posts

    Posted 30 Jun 2010 Link to this post

    Hello Robert Lautenbach,

    Sorry for the delayed answer. On principle to be able to delete the items both from the RadListBox and the database, the OpenAccessDataSource should be configured to allow deletes. Furthermore, you need to set the DataKeyField of the RadListBox to the identifier of the record you want to delete. Finally, you also need to set AllowAutomaticUpdates and AutoPostBackOnDelete in the RadListBox to true.

    However, you seem to have encountered a problem with our RadListBox and it will be fixed. Once again, we are sorry for the inconvenience this might have caused you. Your Telerik points have been updated.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top