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

Overriding delete functionality

3 Answers 113 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael Fooks
Top achievements
Rank 1
Michael Fooks asked on 16 Feb 2010, 02:54 AM
With the gridview I need to override the delete functionality...When a user hits the delete key on a row in the grid I want to set my entity to Inactive, rather than remove it from the collection.

I tried hooking up KeyDown but it never fires for the delete key, the default functionality of removing the row happens.
I tired hooking up KeyDown with CanUserDeleteRows set to false and the key down never fires for the delete key.
I can use other keys such as backspace etc. but our users want to use delete.

The only thing that seemed to work was to handle the Deleting event and do what I want and set e.Cancel to true. The problem with this event is I can't selectivly remove from the collection ie. if my record is new/unsaved and they hit delete i want it removed but if it's a saved record that they delete i want it marked on screen as inactive. The cancel seems to be an all or nothing. 

What's the best way to do the functionality that i need?

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 18 Feb 2010, 03:57 PM
Hello Bronwen Zande,

Well, the problem is that whenever a record is deleted it will be removed from the grid. One possible way to implement the desired functionality is to introduce a new property on your data items called IsDeleted, or create a ViewModel that has this property. The idea is to mark items as removed without actually removing them from the collection (until the removal is actually needed). Once an item is marked as deleted we disable its corresponding row so that it becomes inactive.

I am not sure if that approach will work for your scenario but I have attached a sample project that you could use as a reference. 


Sincerely yours,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Usame Esendir
Top achievements
Rank 1
answered on 22 Feb 2010, 11:46 AM
Hi,
It doesn't seem to be useful to use Deleting event, lets think about a base class binded as datacontext and has List<T> named Items.
When we bind the Items to grid it works fine.
But when I want to delete I cannot catch the deleted item in the base class.

I do not want to implement Deleting event into every user control that uses the grid. I would like to know which method is called to delete the items in the list, so I will override that method. I have tried Remove, RemoveAt, RemoveRange but none of them works. Does grid changes the object inside and assigns the DataContext on every change?

Hope there is a way around.
Thanks,
Usame Esendir
0
Milan
Telerik team
answered on 24 Feb 2010, 03:48 PM
Hello Usame Esendir,

RadGridView will call the "void Remove(object value)" of the IList inteface when deleting items.  


Kind regards,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Michael Fooks
Top achievements
Rank 1
Answers by
Milan
Telerik team
Usame Esendir
Top achievements
Rank 1
Share this question
or