My client wants that when tabbing through DataGridView cells the next current cell to be other than the default one. What\'s the best way to accomplish this?
Mr. Ruslan code did not worked for me. By fetching his idea, i made some change in code.
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
if(dataGridView1.CurrentCell.ReadOnly)
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;
}