Создайте свой собственный DataGridView, переопределите метод ProcessTabKey. По логике, используйте SetCurrentCellAddressCore для установки следующей активной ячейки.
Обратите внимание, что реализация этого метода по умолчанию учитывает множество различных условий, таких как режим выбора, режим редактирования, состояния строк, границы и т. Д.
Редактировать
Кроме того, вы можете обрабатывать события KeyUp / KeyDown. Хотя в этом есть какое-то странное поведение, и я не тратил много времени, это должно сделать:
Установите для свойства StandardTab сетки значение True и добавьте следующий код:
private void Form1_Load(object sender, EventArgs e)
{
// TODO: Load Data
dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
if (dataGridView1.CurrentCell.ReadOnly)
dataGridView1.CurrentCell = GetNextCell(dataGridView1.CurrentCell);
}
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
dataGridView1.CurrentCell = GetNextCell(dataGridView1.CurrentCell);
e.Handled = true;
}
}
private DataGridViewCell GetNextCell(DataGridViewCell currentCell)
{
int i = 0;
DataGridViewCell nextCell = currentCell;
do
{
int nextCellIndex = (nextCell.ColumnIndex + 1) % dataGridView1.ColumnCount;
int nextRowIndex = nextCellIndex == 0 ? (nextCell.RowIndex + 1) % dataGridView1.RowCount : nextCell.RowIndex;
nextCell = dataGridView1.Rows[nextRowIndex].Cells[nextCellIndex];
i++;
} while (i < dataGridView1.RowCount * dataGridView1.ColumnCount && nextCell.ReadOnly);
return nextCell;
}