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
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?
Didie
Telerik
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 >>
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!
}
}
}
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
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 >>
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.
I have attached my test project. Would you please let me know how should I change it to reproduce the issue?
Regards,Didie
Telerik
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 >>
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...