【发布时间】:2021-06-06 03:45:54
【问题描述】:
我想在 datagridview 中设置 Tab 键顺序。
product name | unit price | qty | amount
我希望在我选择产品的那一刻,应该选择数量单元格。一旦我输入数量并点击标签,它应该会转到下一行..
这是我迄今为止尝试过的
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;
}
【问题讨论】:
标签: c# .net winforms datagridview desktop-application