This is a migrated thread and some comments may be shown as answers.

Cancel Insert - wrong EditOperationType

7 Answers 28 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jen
Top achievements
Rank 1
jen asked on 25 Jul 2013, 06:10 PM
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?

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Jul 2013, 11:09 AM
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 >>
0
jen
Top achievements
Rank 1
answered on 30 Jul 2013, 12:22 PM
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!

         }

     }
}

0
Dimitrina
Telerik team
answered on 30 Jul 2013, 12:59 PM
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 >>
0
jen
Top achievements
Rank 1
answered on 30 Jul 2013, 01:04 PM
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.

 

 

 

 

 

0
Dimitrina
Telerik team
answered on 30 Jul 2013, 01:12 PM
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 >>
0
jen
Top achievements
Rank 1
answered on 30 Jul 2013, 01:31 PM
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...  
0
jen
Top achievements
Rank 1
answered on 30 Jul 2013, 01:40 PM
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
Tags
GridView
Asked by
jen
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
jen
Top achievements
Rank 1
Share this question
or