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

delete inserted row on cancel

7 Answers 260 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Franziska
Top achievements
Rank 1
Franziska asked on 12 Oct 2011, 07:49 AM
Hi!

I am inserting new rows with the INSERT key. Once a row was inserted, it can be edited by the user.
I want to delete the newly inserted row, if the user cancels the edit mode with the ESC key. 

What is the easiest way to achieve this?

Thanks and regards,

Franziska

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 14 Oct 2011, 12:58 PM
Hi Franziska,

I am not sure if I understand you the right way. What I understand is that you press the Insert key. Then you edit the newly inserted row. Then you want to delete this row before you have finished with the editing.

If this is the case,  then the default behavior of the RadGridView will delete the inserted row when you press the ESC key for a second time.

If I have misunderstood you, could you please explain me where am I wrong?

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Franziska
Top achievements
Rank 1
answered on 24 Oct 2011, 01:04 PM
Dear Didie,

Sorry for my late response.

You understood me correctly, but my Grid does not show this standard behavior.
Is there a property on the Grid which has to be set?
Or is there a property on the collection which is checked by the grid, before it can delete the added item again?

I already have had this problem once, where the Grid had some inconsistent way to check for different actions.
For example, when inserting with the INSERT key, the CanUserInsertRows property of the Grid is checked, whereas when deleting a row with the DELETE key, the AllowRemove property of the IBindingList is checked instead of the CanUserDeleteRows property of the Grid.

Thanks,

Franziska
0
Franziska
Top achievements
Rank 1
answered on 24 Oct 2011, 05:47 PM
What I forgot to ask.

Is there an event which I can use to delete the newly added item on ESCAPE?

In some cases, I have to add my e.NewObject manually, e.g. to insert it after the selected row in the Grid. So I am canceling the AddingNewDataItem. So I guess I have to implement my own "delete the just added object" logic?!

Or is there an easier way to add the new object after the currently selected row?

Thanks, 
Franziska
0
Dimitrina
Telerik team
answered on 25 Oct 2011, 04:20 PM
Hi Franziska,

 If you would like to add your e.NewObject, you could do this inside AddingNewDataItem. 

I am still a little bit confused by your explanation. Do you want to insert the new added object after the selected row in the Grid? Why do you want to delete the just added object?

I attach a sample project showing how the Escape functionality is working.
Please check it. After insert a new row with the INSERT key, you should press the ESC key two times in order to reject the added row.

I would be more helpful you you could change the sample project to show me the wrong behavior.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Franziska
Top achievements
Rank 1
answered on 25 Oct 2011, 05:46 PM
Dear Didie,

Thanks for the example project.

If you would like to add your e.NewObject, you could do this inside AddingNewDataItem. 
Thats how I do it. But in order to insert my item after the selected item in the grid I have to do something like this:

private void clubsGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
    var club =  new Club("Just inserted club", DateTime.Now, 50);
 
    var gridView = sender as RadGridView;
    var viewModel = gridView.DataContext as MyViewModel;
    var index = viewModel.Clubs.IndexOf(gridView.SelectedItem as Club);
          viewModel.Clubs.Insert(index + 1, club);
    e.Cancel = true;
}

I am still a little bit confused by your explanation. Do you want to insert the new added object after the selected row in the Grid? Why do you want to delete the just added object?
Yes, I want to add after the selected row. Is there a better way then described above?
If not, I need a way to delete the currently added object manually.

I attach a sample project showing how the Escape functionality is working.
Please check it. After insert a new row with the INSERT key, you should press the ESC key two times in order to reject the added row.


Just found the problem why it did not work for me. The ESCAPE button does not work with BindingLists! Even if I set the AllowRemove property true.


Thanks,

Franziska
0
Dimitrina
Telerik team
answered on 27 Oct 2011, 12:31 PM
Hello Franziska,

 Thank you for clarifying this. I have changed the sample project, so that the GridView is bound to a BindingList instead of an ObservableCollection. The functionality the you have described is working fine in my project.

Please check it and see how is it different from yours?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Franziska
Top achievements
Rank 1
answered on 27 Oct 2011, 12:58 PM
Dear Didie,

Really funny behavior:
This only occures if you work with BindingList AND define e.NewObject = new Club(...).
If you do not provide a new object, it works with BindingList.

Regards,
Franziska
Tags
GridView
Asked by
Franziska
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Franziska
Top achievements
Rank 1
Share this question
or