datagrid navigation with keyboard

I am developing an application that will run on all platforms but in windows platform.  I want to navigate with keyboard on windows. When I press enter key, it should enter edit mode and again pressing enter key it will come in endedit mode and cursor should move to next cell. Pressing down arrow key, it should add new row and move cursor to new row, first cell. while entering editing mode and coming out from editing mode, it should fire events.

I have read all events but I want a example that combines all events together to fulfill above requirements.


2nd point, I have GridComboboxcolumn and that should be populated from data table. how it can be possible.

 


Thanking you.





2 Replies

SY Suthi Yuvaraj Syncfusion Team September 14, 2022 08:18 AM UTC

Hi Amish,


#Regarding KeyNavigation Event on Windows Platform


We would like to let you know that Key Navigation can be customized using DataGrid.SelectionController , here ProcessKeyDown gives the value of Key that you have pressed on keyboard as KeyCode , using keycode you can customize the function of each key, we have attached the code snippet and workable sample for your reference.


Code Snippet:

dataGrid.SelectionController = new CustomSelectionController(dataGrid);

 

public class CustomSelectionController : GridSelectionController

{

SfDataGrid DataGrid;

public CustomSelectionController(SfDataGrid dataGrid) : base(dataGrid)

{

    DataGrid = dataGrid;

}

protected override void ProcessKeyDown(string keyCode, bool isCtrlKeyPressed, bool isShiftKeyPressed)

{

    if (keyCode == "Enter")

    {

        var itemindex = DataGrid.CurrentCellManager.RowColumnIndex;

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

    }

    if(keyCode == "Down")

    {

        // Customize down key

    }

    else

    {

        // default key action

        base.ProcessKeyDown(keyCode, isCtrlKeyPressed, isShiftKeyPressed);

    }

}


Also please share the details regarding adding new row while pressing the down arrow key , by default arrow keys are used to navigate from one cell to another.


#Regarding GridComboboxcolumn and that should be populated from data table


We are currently checking the possibility to achieve your requirement "Populating the data from data table for GridCombobox Column", we will update you with further details on or before September 16, 2022.We will appreciate your patience until then.


Regards,

Suthi Yuvaraj.


Attachment: KeyNavigation_29715cc1.zip


SY Suthi Yuvaraj Syncfusion Team September 16, 2022 02:08 PM UTC

Hi Amish,


Regarding your requirement "Populating the data from DataTable for GridComboBox column", you can achieve it by populating the data as datatable and converting it to IEnumerable<T> collection or an ObservableCollection<T> and assigned it as ItemSource of GridComboBoxColumn , where GridComboBoxColumn itemsource datatype must be a collection type. We have attached the runnable sample for your reference , also you can customize the sample as you need.


Also Please refer the below documentation for binding with datatable:

UG Link: Data Binding in Xamarin DataGrid control | Syncfusion


Please let us know if you need any further assistance.


Regards,

Suthi Yuvaraj.


Attachment: DataTable_640e76a6.zip

Loader.
Up arrow icon