Menu

CPersistentCollection - Editing an item?

2004-07-27
2004-07-28
  • Nobody/Anonymous

    I'm just wondering if I'm missing something...

    Taking the example from the tutorial - there is an Order Header with Order Items.  There are facilities to Add and Delete items, but the Item property of the collection is ReadOnly.

    What is the preferred method for editing an item - for example, to change the quantity of the Order Item?

    Thanks,
    Gary.

     
    • Richard Banks

      Richard Banks - 2004-07-27

      The items in a CPersistentColelction are readonly, but the objects they hold are not.  What this means is that to add/remove items from the collection you must use the appropriate methods.

      However to change an object is pretty simple.  To change the quantity (for example) use the following:

      DirectCast(m_order.OrderLines.Item(0), COrderLine).Quantity = 4

      - Richard

       
    • Nobody/Anonymous

      Ah - yes.

      I now see what my problem is.  When I change an item, it is not marking the parent object as being Dirty.  The Add/Remove methods do, but changing the item as above doesn't.  The result is that nothing is saved if only the item has been changed.

       
    • Richard Banks

      Richard Banks - 2004-07-28

      Yes, you are correct.  Add/Remove dirties the parent object because the collection itself has changed and therefore the parent must be resaved.

      Modifying a single object in the collection won't dirty the parent as the parent object itself doesn't need saving, only the child object does.

      - Richard.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.