KeyDown event not triggering on arrow up and down

2 posts, 0 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 26 Mar 2014 Link to this post

    If I type a letter it goes to the event, but not the arrow keys.

    KeyUp does catch the arrow keys, so that's what I'm going to use


    I'm basically doing this to put things in edit mode on the arrow up and arrow down:
    private void handleArrows(object sender, KeyEventArgs e)
    {
        RadGridView rgv = (RadGridView)sender;
        if (e.Key == Key.Down)
        {
            RadGridViewCommands.MoveDown.Execute(null);
            rgv.BeginEdit();
            e.Handled = true;
        }
        if (e.Key == Key.Up)
        {
             RadGridViewCommands.MoveUp.Execute(null);
            rgv.BeginEdit();
            e.Handled = true;
        }
    }
  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 28 Mar 2014 Link to this post

    Hi Dan,

    indeed, the KeyDown event will not be raised because GridView handles it internally.  In order to use it you have to subscribe to it with HandledEventsToo set to true. Please check the following code snippet for a reference:

    this.gridView.AddHandler(RadGridView.KeyDownEvent, new KeyEventHandler(gridView_keyDown), true);
                       .
                       .
                       .
    private void gridView_keyDown(object sender, KeyEventArgs e)
           {
               RadGridView rgv = (RadGridView)sender;
               if (e.Key == Key.Down)
               {
                   RadGridViewCommands.MoveDown.Execute(null);
                   rgv.BeginEdit();
                   e.Handled = true;
               }
               if (e.Key == Key.Up)
               {
                   RadGridViewCommands.MoveUp.Execute(null);
                   rgv.BeginEdit();
                   e.Handled = true;
               }
           }

     



    Regards,
    Yoan
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top