arunasingh 0 Light Poster

Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
DataGridView1.AllowUserToAddRows = True
Dim ri As Integer = DataGridView1.CurrentCell.RowIndex
Dim ci As Integer = DataGridView1.CurrentCell.ColumnIndex
e.SuppressKeyPress = True
FindNextCell(DataGridView1, ri, ci + 1) 'checking from Next
End If
End Sub

Sub FindNextCell(ByVal dgv As DataGridView, ByVal rowindex As Integer, ByVal columnindex As Integer)
Dim found As Boolean = False
While dgv.RowCount > rowindex
'DataGridView1.AllowUserToAddRows = True
While dgv.Columns.Count - 1 > columnindex
If Not (dgv.Rows(rowindex).Cells(columnindex)).ReadOnly Then
dgv.CurrentCell = dgv.Rows(rowindex).Cells(columnindex)
Exit Sub
Else
columnindex += 1
End If
End While
rowindex += 1
columnindex = 0
End While
End Sub


through this i can set focus to next cell in the same row, now when i search data on the basis of some no then that data is displayed to the datagridview.And after that through this code i can press enter the set focus to next cell,now when i reach suppose 4 th cell and when i press enter i want that a new row is created in the datagrdview and above row is copied to the new row

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.