我在Windows窗体中有一个数据网格视图,编辑值时的默认行为是在单元格版本之后,当我按回车键时,所选行将更改为下一个
我的问题是单元格编辑后更改列而不是将行更改为下一个
你应该处理dataGridView1_KeyDown
事件。
我没有真正测试代码,但我认为它是这样的。
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
dataGridView1.CurrentCell = dataGridView1[col, row];
e.SuppressKeyPress = true;
e.Handled = true;
}
}