This is a migrated thread and some comments may be shown as answers.

How to focus cell in RadGridView after Enter key ! Please help me

1 Answer 511 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tien
Top achievements
Rank 1
Tien asked on 11 Mar 2014, 03:09 AM
 Public Overrides Function ProcessKey(ByVal keys As KeyEventArgs) As Boolean
        Try
            If keys.KeyCode = Windows.Forms.Keys.Tab Or keys.KeyCode = Windows.Forms.Keys.Enter Then
                If GridViewElement.Navigator.IsLastColumn(GridViewElement.CurrentColumn) Then
                    'Me.GridControl.ClearSelection()

                    Me.GridControl.GridNavigator.SelectNextRow(1)

                    Dim columnIndex = Me.GridControl.Columns("NewPrice").Index
                    GridViewElement.CurrentRow.Cells("NewPrice").IsSelected = True
                    GridViewElement.CurrentRow.Cells("NewPrice").BeginEdit()

                End If
            End If
        Catch ex As Exception

        End Try
        Return MyBase.ProcessKey(keys)
    End Function

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 13 Mar 2014, 11:49 AM
Hi Tien,

Thank you for writing.

To handle the Enter key you need to create your own data row behavior and replace the default one with it:
Class MyDataRowBehavior
    Inherits GridDataRowBehavior
    Protected Overrides Function ProcessEnterKey(keys As KeyEventArgs) As Boolean
        If GridViewElement.Navigator.IsLastColumn(GridViewElement.CurrentColumn) Then
            Me.GridControl.GridNavigator.SelectNextRow(1)
            Me.GridControl.CurrentColumn = Me.GridControl.Columns("DecimalColumn")
            Me.GridControl.BeginEdit()
        End If
 
        Return True
    End Function
End Class
 
DirectCast(radGridView1.GridBehavior, BaseGridBehavior).UnregisterBehavior(GetType(GridViewDataRowInfo))
DirectCast(radGridView1.GridBehavior, BaseGridBehavior).RegisterBehavior(GetType(GridViewDataRowInfo), New MyDataRowBehavior())

I hope that the provided information addresses your question. 

Regards,
Stefan
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
GridView
Asked by
Tien
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or