BoldDesk®Customer service software with ticketing, live chat & omnichannel support, starting at $99/mo for unlimited agents. Try for free!
Hello,
The title explain it all, I would like to navigate to the next cell of the datagrid when I press the up or down arrow instead of increase the value of the date in the GridDateTimeColumn.
The enter key do the jobs but we would like the same behavior for the arrow up/down.
Thank you
Hi Nicolas Wagener,
Your requirement to navigate to the next cell of the SfDataGrid when pressing
the up or down arrow instead of increasing the value of the date in the GridDateTimeColumn
can be achieved by using the MoveCurrentCell helper method and customizing the PreviewKeyDown
event. Refer to the below code snippet,
// Event subscription sfDataGrid.PreviewKeyDown += OnPreviewKeyDown;
//Event customization private void OnPreviewKeyDown(object sender, KeyEventArgs e) { // Check if the key pressed is Up or Down arrow key if (e.Key == Key.Up|| e.Key == Key.Down) { // Get the current cell DataColumnBase currentCell = sfDataGrid.SelectionController?.CurrentCellManager?.CurrentCell;
// Check if the current cell is not null if (currentCell != null) { // Get the current cell row index int currentRowIndex = currentCell.RowIndex; // Get the current cell column index int currentColumnIndex = currentCell.ColumnIndex;
// Check if the current cell is DateTime column if (sfDataGrid.Columns[currentColumnIndex].CellType == "DateTime") { // End the edit when the current cell is first or last row if (currentRowIndex == sfDataGrid.GetFirstRowIndex() || currentRowIndex == sfDataGrid.GetLastRowIndex()) this.sfDataGrid.SelectionController.CurrentCellManager.EndEdit(); else // Move focus to the next cell if (e.Key == Key.Up && currentRowIndex > sfDataGrid.GetFirstRowIndex()) { // Move focus to the previous cell sfDataGrid.MoveCurrentCell(new RowColumnIndex(currentRowIndex - 1, currentColumnIndex)); } else if (e.Key == Key.Down && currentRowIndex < sfDataGrid.GetLastRowIndex()) { // Move focus to the next cell sfDataGrid.MoveCurrentCell(new RowColumnIndex(currentRowIndex + 1, currentColumnIndex)); } } } } } |
UG
Link: Editing in WPF
DataGrid control | Syncfusion
Selection
in WPF DataGrid control | Syncfusion
Find the modified sample demo in the attachment.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.
Hello Vijayarasan,
Thank you it's a perfect trick.
Have a nice day
Nicolas Wagener,
We are glad to know that the reported problem has been resolved at your end.
Please let us know if you have any further queries on this. We are happy to
help you😊.