How to disable per cell tab stop of DataGridView in C# ?
If users focus on DataGridView and press 'Tab', I hope the next control would be focused, not focusing on next cell of DataGridView.
How can I do that?
This will make the next control get focus:
private void DataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
DataGridView1.Enabled = false;
DataGridView1.GetNextControl(DataGridView1, true).Focus();
DataGridView1.Enabled = true;
e.Handled = true;
}
}
When using the KeyUp the datagridview still moves one cell further before giving up focus. If you want to undo that you can add this line of code:
DataGridView1.CurrentCell = DataGridView1.Rows[DataGridView1.CurrentCell.RowIndex].Cells[DataGridView1.CurrentCell.ColumnIndex - 1];
DataGridView1.Enabled = false;
DataGridView.GetNextControl(DataGridView1, true).Focus();
DataGridView1.Enabled = true;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments