I'm using an sfDataGrid that contains several GridComboBoxColumns.
When adding a new row, if I use the tab keys to navigate into a combobox cell and then press an alphanumeric, the combo immediately selects an appropriate value from its items. This behaviour is great and exactly what I'm looking for. Notably, when I tab in the combo box is showing, so presumably the cell has already entered edit mode. I also get this behaviour if I mouse click into the column.
However, if I'm not in the "New Row" (i.e. a row that has already been committed to the grid's source) I don't get the same behaviour. Instead, when I tab in, the combo box does not immediately show - so I guess the cell's not in edit mode? The user now requires two keystrokes to select an entry. The first to get the combo box to show and the second to actually make the selection.
I also notice that navigating into the cell using the arrow keys rather than the tab key, again, it doesn't appear to enter edit mode so requires an extra key stroke. This applies to both the new row and to committed rows.
Is there a way to get the tab key on committed rows and the arrow keys on all rows to behave in the same way as a mouse click - ie put the cell straight into edit mode.
I've uploaded a dummy project that demonstrates the behaviour I'm seeing.
Hi Declan Hillier,
Solution 1:
Your requirement to enter edit mode by pressing the tab and arrow keys pressing
in data rows in SfDataGrid can be achieved by customizing the default row
selection behaviors by overriding GridSelectionController class and setting it to
SfDataGrid.SelectionController. Please refer to the below code snippet,
//Inherits the GridSelectionController Class public class GridSelectionControllerExt : GridSelectionController { public GridSelectionControllerExt(SfDataGrid datagrid) : base(datagrid) { }
//overriding the ProcessKeyDown Event from GridSelectionController base class protected override void ProcessKeyDown(KeyEventArgs e) { base.ProcessKeyDown(e); if (e.Key == Key.Tab || e.Key == Key.Down || e.Key == Key.Up || e.Key == Key.Left || e.Key == Key.Right) { if (DataGrid != null) { if (DataGrid.SelectionController != null) { if (DataGrid.SelectionController.CurrentCellManager != null) { if (DataGrid.SelectionController.CurrentCellManager.CurrentCell != null) { //Here call the BeginEdit method to enter the edit mode in SfDataGrid if (!DataGrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing) DataGrid.SelectionController.CurrentCellManager.BeginEdit(); } } } }
} } } |
UG Link: https://help.syncfusion.com/wpf/datagrid/selection#customizing-selection-behaviors
KB Link: https://www.syncfusion.com/kb/3815/how-to-change-the-enter-key-behavior-in-sfdatagrid
Solution 2:
Your requirement to enter edit mode by pressing the tab and arrow keys pressing
in data rows in SfDataGrid can be achieved by customizing the CurrentCellActivated
event. Please refer to the below code snippet,
//Event subscription this.AssociatedObject.CurrentCellActivated += OnCurrentCellActivated;
//Event customization private void OnCurrentCellActivated(object sender, CurrentCellActivatedEventArgs e) { var datagrid = sender as SfDataGrid;
if (datagrid != null) { if (datagrid.SelectionController != null) { if (datagrid.SelectionController.CurrentCellManager != null) { if (datagrid.SelectionController.CurrentCellManager.CurrentCell != null) { //Here call the BeginEdit method to enter the edit mode in SfDataGrid if (!datagrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing && e.ActivationTrigger == ActivationTrigger.Keyboard) datagrid.SelectionController.CurrentCellManager.BeginEdit(); } } } } } |
UG Link: https://help.syncfusion.com/wpf/datagrid/selection#currentcellactivated-event
https://help.syncfusion.com/wpf/datagrid/editing#beginedit
Please find the sample in the attachment and let us know if you have any
concerns about this.
Regards,
Vijayarasan S
If this post is helpful, please consider Accepting it as the
solution so that other members can locate it more quickly.
I tried solution 2 and it worked like a charm. Thank you.
Hi Declan Hillier,
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😊.
Regards,
Vijayarasan S