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

Ignore F2, Del, Ins key presses

4 Answers 185 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Larry
Top achievements
Rank 1
Larry asked on 25 Jun 2010, 07:25 PM
How can I get a RadGridView to ignore F2, Del, Ins if it has keyboard focus?  I have CommandBindings defined to handle these key presses and would like to have these CommandBindings executed.  I don't want to ignore all keyboard input in the RadGridView however as I'd still like to navigate the rows in the RadGridView with arrow keys.

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 28 Jun 2010, 01:56 PM
Hi Larry,

 
The recommended way for changing the keyboard navigation is to create your own class CustomKeyboardCommandProvider, to predefine the behavior of the desired keys and to set it as the default KeyboardCommandProvider for the grid. I am sending you a sample project illustrating how to dismiss the F2, Del and Ins buttons.

Kind regards,
Maya
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
Uli
Top achievements
Rank 1
answered on 30 Jul 2010, 10:08 AM
Hi Maya,

I've got the same problem as Larry with a WPF application. I downloaded your sample project, converted it to a WPF application using RadControls 2010 Q2 and run it.

The CustomKeyboardCommandProvider.ProvideCommandsForKey method is only called for the Ins, F2 and several other keys but not for the Del key. But the Del key is the one a need most.

Any suggestions?

Uli
0
Maya
Telerik team
answered on 30 Jul 2010, 01:54 PM
Hi Uli,

Indeed, the Delete command in RadGridView is handled differently compared to that in Silverlight. So, what you can do in this case is to use the PreviewKeyDown and KeyDown events of the grid. You can cancel the action of the Delete key in the first one or implement custom logic in the second one. For example:

public MainWindow()
{
   InitializeComponent();
   this.gridView.PreviewKeyDown += new KeyEventHandler(gridView_PreviewKeyDown);
    
   this.AddHandler(RadGridView.KeyDownEvent, new KeyEventHandler(gridView_KeyDown), true);
   this.gridView.KeyDown += new System.Windows.Input.KeyEventHandler(gridView_KeyDown);
}
 
void gridView_PreviewKeyDown(object sender, KeyEventArgs e)
{
   //in case the key used is "Del", you can cancel its action
   if(e.Key == Key.Delete)
   {
    e.Handled = true;
   }
             
}
 
        void gridView_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            //custom logic
            MessageBox.Show("Hi!");
        }
        


 The line:
this.AddHandler(RadGridView.KeyDownEvent, new KeyEventHandler(gridView_KeyDown), true);

allows you to "see" events that have already been handled, which is the case with the KeyDown event.

However, we would investigate a bit more the issue and we would consider changing the way Delete command is implemented so that "Delete" could be handled as all the other keys.

Sincerely yours,
Maya
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
Maya
Telerik team
answered on 04 Aug 2010, 10:23 AM
Hi Uli,

We have updated the way the Delete Command is handled in WPF and now you will be able to apply the method with the CustomKeyBoardCommandProvider. When implementing it, you may use as a reference this blog post.
That functionality will be available in our next Service Pack. 

Sincerely yours,
Maya
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
Larry
Top achievements
Rank 1
Answers by
Maya
Telerik team
Uli
Top achievements
Rank 1
Share this question
or