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

Excel-style Delete key behavior in GridView

1 Answer 427 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 16 Sep 2016, 11:42 PM
Is there any way to implement Excel-style "Delete" key behavior for selected cells in RadGridView? I want the Delete key to clear the selected cell's contents, setting the underlying data-bound property value to null or whatever the default value of the databound type is.
I haven't been able to find any info on whether this is possible-- somebody posted a related issue in 2010 (http://www.telerik.com/forums/cleaar-the-cell-content-at-runtime) but it does not appear to have been resolved.
Could someone please help me implement this behavior? I'm currently trying to override the delete key in a custom KeyboardCommandProvider but none of the RadGridViewCommand options do what I want.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 19 Sep 2016, 12:18 PM
Hello Aaron,

You can achieve the desired behavior by using a custom KeyboardCommandProvider and handling the Delete key by overriding its ProvideCommandsForKey method. Here's an example:

public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
    List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
 
    if (key == Key.Delete)
    {
        commandsToExecute.Clear();
        foreach (var cell in parentGrid.SelectedCells)
        {
            var property = cell.Column.UniqueName;
            var club = cell.Item as Club;
            club.GetType().GetProperty(property).SetValue(club, null);
        }
         
    }
 
    return commandsToExecute;
}

Would such an approach be suitable for your requirements?

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Aaron
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or