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.
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) 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.
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.
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.