Begin cell edit when navigating around table using cursor keys

We are using a datagrid in Windows to enable data entry. On Xamarin we used a custom selection controller to ensure that editing would begin when a cell was selected using cursor keys, rather than a mouse click having to be used.


How can we achieve the same result in MAUI?


1 Reply

SD Sethupathy Devarajan Syncfusion Team May 19, 2025 09:33 AM UTC

Hi Matthew,


You need to perform editing when a cell is selected using a keyboard key, rather than a mouse click. We have addressed your request with a custom selection controller. We have shared the code snippet and sample for your reference.

Code snippet:

 public partial class MainPage : ContentPage

 {

     public MainPage()

     {

         InitializeComponent();

         sfGrid.DataGridLoaded += SfGrid_DataGridLoaded;

         sfGrid.SelectionController = new CustomRowSelectionController(this.sfGrid);

     }

 

     private void SfGrid_DataGridLoaded(object? sender, EventArgs e)

     {

         sfGrid.GetVisualContainer().Focus();

     }

 }

 

 public class CustomRowSelectionController : DataGridRowSelectionController

 {

     public CustomRowSelectionController(SfDataGrid dataGrid) : base(dataGrid)

     {

     }

     protected override void ProcessKeyDown(KeyEventArgs args, bool isCtrlKeyPressed, bool isShiftKeyPressed)

     {

         base.ProcessKeyDown(args, isCtrlKeyPressed, isShiftKeyPressed);

 

         if (DataGrid?.CurrentCell != null &&

         (args.Key == KeyboardKey.Left || args.Key == KeyboardKey.Right ||

          args.Key == KeyboardKey.Up || args.Key == KeyboardKey.Down ||

          args.Key == KeyboardKey.Tab || args.Key == KeyboardKey.Enter))

         {

             DataGrid.BeginEdit(DataGrid.CurrentCell.RowIndex,DataGrid.CurrentCell.ColumnIndex);

         }

     }

 }


If you have any misunderstandings or if your needs differ, please provide clear details about your use case. You can include additional information regarding the expected behavior. This extra detail will enable us to thoroughly address your request and provide an appropriate solution.

Regards,
Sethupathy D.


Attachment: SfDataGridSample_a8b1c1f2.zip

Loader.
Up arrow icon