using enter key tab to next row in sfdatagrid

Please provide solution in vb.net.

If we press enter focus moves to next column and in last column on pressing enter focus moves to next row first column.

If we want using enter key to skip not allowed to edit columns .

Col1(AllowEditing False) | Col2(AllowEditing False) | Col3(AllowEditing True) | Col4(AllowEditing True)

On Pressing enter from col3 focus should be on col4.
And from Col 4 focus should be in next row, first cell.

3 Replies

DM Dhanasekar Mohanraj Syncfusion Team June 13, 2023 02:24 PM UTC

Hi Urvik,

Your requirement to “Change the Enter key's behavior like the Tab key's behavior” will be achievable by overriding the HandleKeyOperations method in RowSelectionController in SfDataGrid. Please refer to the below code snippet,

'set the customized CustomSelectionController to SfDataGrid.SelectionController when RowSelection applied in SfDataGrid

sfDataGrid1.SelectionController = New CustomSelectionController(sfDataGrid1)

'Inherits the RowSelectionController Class

Public Class CustomSelectionController

    Inherits RowSelectionController

 

    Private DataGrid As SfDataGrid

 

    Public Sub New(ByVal sfDataGrid As SfDataGrid)

        MyBase.New(sfDataGrid)

        Me.DataGrid = sfDataGrid

    End Sub

 

    'overriding the HandleKeyOperations Event from RowSelectionController base class

    Protected Overrides Sub HandleKeyOperations(ByVal args As KeyEventArgs)

        If args.KeyCode = Keys.Enter Then

            ' Assigning the state of Tab key Event handling to Enter key

            Dim arguments As New KeyEventArgs(Keys.Tab)

            MyBase.HandleKeyOperations(arguments)

 

            'or like set the tab key

            'SendKeys.Send("{Tab}")

            Return

        End If

 

        MyBase.HandleKeyOperations(args)

    End Sub

 

End Class


Here we have prepared the sample based on the above suggestion, please have a look at this.

Regards,
Dhanasekar M.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDataGridDemo_450b0aab.zip


UR Urvik June 16, 2023 08:12 AM UTC

Thats great to override the Enter key to Tab key but I don't want focus on 1st and 2nd column. For now focus goes from 1st column from previous row last column.


Ok maybe my mistake in the question, I want focus to move from col4 to next row col 3.. Focus should only move in col 3 and col 4.




DM Dhanasekar Mohanraj Syncfusion Team June 19, 2023 03:57 PM UTC

Urvik,

Your requirement to “move the current cell only for editable columns” will be achievable by overriding the ProcessSelectionAndCurrentCell as shown below,

Protected Overrides Sub ProcessSelectionAndCurrentCell(rowColumnindex As RowColumnIndex)

    ' Restricting the navigation for the non-editable columns.

    For i As Integer = 0 To DataGrid.Columns.Count - 1

        If DataGrid.Columns(i).AllowEditing = True Then

            DataGrid.MoveToCurrentCell(New RowColumnIndex(rowColumnindex.RowIndex, i))

            Return

        End If

    Next

    MyBase.ProcessSelectionAndCurrentCell(rowColumnindex)

End Sub


Here, we have attached the modified sample for your reference, please have a look at this.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: SfDataGridDemo__46d5c310.zip

Loader.
Up arrow icon