Prevent Silverlight DataGrid processing with an input key

I have a datagrid in a Silverlight application. Clicking on the first line and then pressing the Enter key causes the selection to move to the next line. I do not want this behavior - the Enter key is used for completely different purposes on this screen.

I understand that this is part of the editing framework, but I need a way to disable it. I tried setting IsReadOnly to True (even if the control is not technically read-only), and this had no effect.

I am attached to a KeyDown event using a datagrid, but it does not fire when the Enter key is pressed. It works great for other keys.

I'm at a dead end. Thank you for your help.

+4
source share
1 answer

Yes, it is annoying.

As far as I know, the only option is to create your own control that inherits from the DataGrid and do what is necessary before transferring the event to the base.

public class NewDataGrid : DataGrid { protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Key.Enter) { //do what is needed here e.Handled = true; } base.OnKeyDown(e); } } 
+4
source

All Articles