Answer the question
In order to leave comments, you need to log in
How to finish editing a DataGrid cell with the arrows on the keyboard?
By default, editing a DataGrid cell is terminated when the Enter key, tab key is pressed, or when focus is lost.
But it was necessary to make it so that this would also happen when you press the UP and Down keys (up and down arrows).
By default, when editing the Grid, these keys do not respond.
I feel that the solution should be on the surface, but I don’t really want to reinvent the wheel.
Answer the question
In order to leave comments, you need to log in
Try handling the PreviewKeyDown event :
private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Up || e.Key == Key.Down)
{
dataGrid.CancelEdit();
}
}
<DataGrid x:Name="dataGrid" PreviewKeyDown="dataGrid_PreviewKeyDown" ...>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question