.net - override navigation of datagridview using enter key -


Text after "div class =" itemprop = "text">

If you override how to enter a key in a DataGridView, then will it set the focus to the next column rather than the next line?

All you need to do is handle the KeyDown event in DataGridView and handler, if pressed is checked If the current key is an enter key, then just set the CurrentCell of DataGridView to the next cell (also check if this is the last cell of this line, in that case, move it to the first cell of the next line.)

  Personal sub-DataGridView1_KeyDown (ByVal and KeyEventArgs as object, byVal sender) handles DataGridView1.KeyDown if E.Code = Keys.Enter then Dim numcols as Integer = DataGridView1.ColumnCount Dim as Number Integre = DataGridView1.RowCount dim currCell DataGridViewCell = DataGridView1.CurrentCell as if currCell.ColumnIndex = numCols - 1 Then if currCell.RowIndex & lt; Numrows - 1 then End DataGridView1.CurrentCell = DataGridView1.Item (0, currCell.RowIndex +1) or else DataGridView1.CurrentCell = DataGridView1.Item (currCell.ColumnIndex + 1, currCell.RowIndex) if e.Handled = true end then end End Sub  

Comments