Click here to Skip to main content
14,605,760 members
Rate this:
Please Sign up or sign in to vote.
See more:
i want enter key work as tab key in datagridview in
Rate this:
Please Sign up or sign in to vote.

Solution 1

Private EditRow As Integer = -1
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        EditRow = DataGridView1.CurrentRow.Index
    End Sub
    Private Sub DataGridView1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
        If e.KeyCode = Keys.Return Then
            If DataGridView1.CurrentRow.Index < DataGridView1.RowCount - 1 AndAlso _
                DataGridView1.CurrentCell.ColumnIndex = DataGridView1.ColumnCount - 1 Then
                DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.CurrentRow.Index + 1)
                Dim cur_cell As DataGridViewCell = DataGridView1.CurrentCell
                Dim col As Integer = cur_cell.ColumnIndex
                col = (col + 1) Mod DataGridView1.Columns.Count
                cur_cell = DataGridView1.CurrentRow.Cells(col)
                DataGridView1.CurrentCell = cur_cell  
            End If
            e.Handled = True

        End If
    End Sub

    Private flag_cell_edited As Boolean
    Private currentRow As Integer
    Private currentColumn As Integer

    Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
    End Sub

    Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
        If EditRow >= 0 Then
            Dim new_row As Integer = EditRow
            EditRow = -1
            DataGridView1.CurrentCell = DataGridView1.Rows(new_row).Cells(DataGridView1.CurrentCell.ColumnIndex)
        End If

    End Sub
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi all,
Please try this
GRIDVIEW1.CurrentCell = GRIDVIEW1.Rows(GRIDVIEW1.Rows.Count -1).Cells(Column_Name.Name)

good luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100