[英]How to use enter as a tab in datagridview
我想使用Enter键替代datagridview中的Tab键。当我在第三列中键入内容时,它有四列,应通过按Enter键将其移至同一行的第四列,它将移至下一行而不是下一行。 我正在使用以下代码
if (e.KeyData == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
if (col < dataGridView1.ColumnCount - 1)
{
col++;
}
else
{
col = 0;
row++;
}
if(row == dataGridView1.RowCount)
dataGridView1.Rows.Add();
dataGridView1.CurrentCell = dataGridView1[col, row];
e.Handled = true;
}
此代码正常工作。 应该为false allowuser添加行。
if (e.KeyCode == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
if (row == dataGridView1.Rows.Count - 1 && col < dataGridView1.Columns.Count - 1)
{
dataGridView1.CurrentCell = dataGridView1.Rows[row].Cells[col + 1];
dataGridView1.Focus();
}
else if (col == dataGridView1.Columns.Count - 1 && row == dataGridView1.Rows.Count - 1)
{
dataGridView1.Rows.Add(1);
dataGridView1.CurrentCell = dataGridView1.Rows[row].Cells[0];
dataGridView1.Focus();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.