We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Force GridComboColumn into edit mode when navigating in using arrow keys or tab key on committed row

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.


Attachment: MainWindow.xaml_a43e641f.Zip

3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team October 7, 2022 12:19 PM

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.


Attachment: Sample_834cd308.zip

Marked as answer

DH Declan Hillier October 10, 2022 05:45 AM

I tried solution 2 and it worked like a charm.  Thank you.



VS Vijayarasan Sivanandham Syncfusion Team October 11, 2022 12:55 AM

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



Loader.
Live Chat Icon For mobile
Up arrow icon