Cancel Insert - wrong EditOperationType

8 posts, 0 answers
  1. jen
    jen avatar
    79 posts
    Member since:
    Jun 2009

    Posted 25 Jul 2013 Link to this post

    Q2 2013.

    I'm trying to work out managing data in an editable grid using the insert row. I am having trouble removing a newly added item from my context when the user cancels the edit of the new item.

    steps:

    1) click to add new item
    2) RadGridView_AddingNewDataItem - initialize new item. Item is an Entity that is detached from any context.
    3) grid inserts the item into collection. The item is now in context.
    4) Press escape twice (why twice? cancel edit cell, then cancel edit row?) - The insert row vanishes and the item isn't visible in the list, but it remains in the context.
    5) RadGridView_RowEditEnded - Here I would like to remove the entity from the context. However since e.EditOperationType == GridViewEditOperationType.Edit instead of GridViewEditOperationType.Insert like I would expect, I cannot delete the item. if I do, then any other row I edit then cancel would also get deleted.

    Is there another event I could use to remove the item from the context, or is e.EditOperationType perhaps set wrong in this case?

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Jul 2013 Link to this post

    Hi,

    What do you mean that the entity remains in the context? In my test the item was added to the bound source collection (when I clicked the Insert key), then it was removed from the source collection after I pressed two times the ESC key.

    I have tested with an ObservableCollection. What is your bound source collection? 

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. jen
    jen avatar
    79 posts
    Member since:
    Jun 2009

    Posted 30 Jul 2013 Link to this post

    for simplicity, I have an entity called Group, which contains a list of child items called Item. The Grid is bound to Group.Items, which is an EntityCollection.

    I could easily achieve what I need, if the RadGridView_RowEditEnded event returned  e.EditOperationType == GridViewEditOperationType.Insert like I would expect, seeing as it was the insert that was ended.

    Note the unreachable code below.

    private void RadGridView_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)

    {

       if (e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert)

         {

         if (e.EditAction == Telerik.Windows.Controls.GridView.GridViewEditAction.Commit)

             {

              //add to context - not needed as the entity is already connected

             // Model.InsertNewIntoContext(e.EditedItem as Item);

             }

         else

             {

             Model.RemoveFeild(e.EditedItem as Item); //unreachable code!

             }

         }
    }

  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Jul 2013 Link to this post

    Hi,

    If you set e.NewObject to be the new instance similar to:

    private void clubsGrid_AddingNewDataItem_1(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
    {
         e.NewObject = new Club("New item", DateTime.Now, 50);
    }
     
    Then the EditOperationType should be Insert. How have you implemented your logic when the AddingNewDataItem event is raised?

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. jen
    jen avatar
    79 posts
    Member since:
    Jun 2009

    Posted 30 Jul 2013 Link to this post

    I do the same:

    private void RadGridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)

    {

         e.NewObject = Model.InitItem();

    }

    when I commit the RadGridView_RowEditEnded event's

    e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Insert Correctly. When canceling, its e.EditOperationType == Telerik.Windows.Controls.GridView.GridViewEditOperationType.Edit regardless of weather it was an insert or a normal edit that was ended.

     

     

     

     

     

  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Jul 2013 Link to this post

    Hello,

    I have attached my test project. Would you please let me know how should I change it to reproduce the issue? 

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. jen
    jen avatar
    79 posts
    Member since:
    Jun 2009

    Posted 30 Jul 2013 Link to this post

    Your example with local classes and ObservableCollections works correctly.

    The difference is I'm working with Entity and EntityCollection, not an ObservableCollection. You would need to add an ADO.NET Entity Data Model to your server side, and connect it to a database, generate the entities, hook it all up via RIA...  
  8. jen
    jen avatar
    79 posts
    Member since:
    Jun 2009

    Posted 30 Jul 2013 Link to this post

    For now I'll just expose my collection through a CollectionViewSource. But I'm pretty sure there is a bug in the control when it comes to EntityCollection. Thanks for your help
Back to Top