4 Answers, 1 is accepted
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.
Maya
the Telerik team
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
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
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.
Maya
the Telerik team