Excel-style Delete key behavior in GridView

2 posts, 0 answers
  1. Aaron
    Aaron avatar
    1 posts
    Member since:
    Jun 2015

    Posted 16 Sep Link to this post

    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.
  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    370 posts

    Posted 19 Sep Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top