我怎样才能改变“进入"时发生的事情?在 DataGridView 上按下了键? [英] How can I change what happens when "enter" key is pressed on a DataGridView?
本文介绍了我怎样才能改变“进入"时发生的事情?在 DataGridView 上按下了键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我编辑一个单元格并按下回车键时,下一行会被自动选中,我想留在当前行...除了 EndEdit 我不想发生任何事情.
when I am editing a cell and press enter the next row is automatically selected, I want to stay with the current row... I want to happen nothing except the EndEdit.
我有这个:
private void dtgProductos_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dtgProductos[e.ColumnIndex, e.RowIndex].Selected = true; //this line is not working
var index = dtgProductos.SelectedRows[0].Cells.IndexOf(dtgProductos.SelectedRows[0].Cells[e.ColumnIndex]);
switch (index)
{
case 2:
{
dtgProductos.SelectedRows[0].Cells[4].Selected = true;
dtgProductos.BeginEdit(true);
}
break;
case 4:
{
dtgProductos.SelectedRows[0].Cells[5].Selected = true;
dtgProductos.BeginEdit(true);
}
break;
case 5:
{
btnAddProduct.Focus();
}
break;
default:
break;
}
}
因此,当我编辑不是最后一行的行时,出现此错误:
so when I edit a row that is not the last one I get this error:
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
推荐答案
我认为您需要覆盖 ProcessEnterKey 才能不将焦点移到下一行.
I think you'll need to override ProcessEnterKey to not advance focus to the next row.
也许 这个线程 会有所帮助.
这篇关于我怎样才能改变“进入"时发生的事情?在 DataGridView 上按下了键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文