Do not enter edit mode on enter/arrow keys

2 posts, 0 answers
  1. Alexander
    Alexander avatar
    77 posts
    Member since:
    Apr 2013

    Posted 24 Feb Link to this post

    Hi!
    Is there a way to _not_ enter the edit mode if the user changes the selected cell using the arrow keys or by pressing enter?
    (Event if the user was in edit mode before). I want to get closer to the behavior of excel.

    Alex

  2. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 29 Feb Link to this post

    Hello Alex,

    For this requirement, you can benefit from the KeyBoard Command Provider mechanism which RadGridView supports. Basically, within the overriden ProvideCommandsForKey() method, you can implement logic as suggested in the snippet below.
    public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
    {
        List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
     
        if (key == Key.Enter)
        {
            commandsToExecute.Clear();
            this.parentGrid.CommitEdit();
        }
        if (key == Key.Tab)
        {
            commandsToExecute.Clear();
            this.parentGrid.CommitEdit();
        }
        return commandsToExecute;
     
    }

    Can you please give the suggestion a try and let me know how it goes?

    Best Regards,
    Stefan X1
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top