Click here to Skip to main content
15,886,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want enter key work as tab key in datagridview in vb.net
Posted

VB
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)
                'SendKeys.Send("{TAB}")
                'SendKeys.Send("{UP}")
            Else
                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
        SendKeys.Send("{TAB}")
   
    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
 
Share this answer
 
v2
Hi all,
Please try this
VB
GRIDVIEW1.CurrentCell = GRIDVIEW1.Rows(GRIDVIEW1.Rows.Count -1).Cells(Column_Name.Name)


good luck
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900