c# - C#在datagridview中按回车键时如何移动更改焦点
问题描述
(对不起,我英语不好。)
嗨,我想在 gridview 中按下回车键时移动到第四个单元格。
如果焦点是第四个单元格,我想移动下一行的第一个单元格。
在gridview的第一个单元格中输入数据> Enter键>移动到当前行的第四个单元格> Enter键>移动到下一行的第一个单元格> ...
我试过这段代码。
private void ProductInfoView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
e.SuppressKeyPress = true;
int irow = ProductInfoView.CurrentCell.RowIndex;
int icolumn = ProductInfoView.CurrentCell.ColumnIndex;
if (icolumn == ProductInfoView.Columns.Count - 1)
{
ProductInfoView.CurrentCell = ProductInfoView[0, irow + 1];
}
else
{
ProductInfoView.CurrentCell = ProductInfoView[icolumn + 3, irow];
}
}
}
但是e.SuppressKeyPress = true; 没有工作。当我按下回车键时,它进入下一行的第一个单元格。
所以,我尝试了另一个代码。
private void ProductInfoView_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
e.SuppressKeyPress = true;
int irow = ProductInfoView.CurrentCell.RowIndex;
int icolumn = ProductInfoView.CurrentCell.ColumnIndex;
if (icolumn == ProductInfoView.Columns.Count - 1)
{
ProductInfoView.CurrentCell = ProductInfoView[0, irow + 1];
}
else
{
ProductInfoView.CurrentCell = ProductInfoView[icolumn + 3, irow];
}
}
}
在这段代码中,移动到第四个单元格有效,但输入键也有效。
焦点移到下一行的第四个单元格。
我该如何解决。
解决方案
推荐阅读
- openstack - 如何在 openstack kolla 中使用 OVN?
- sql-server - 为什么平面文件未在 SSIS 源中加载?
- sql - Select 语句创建序列变量
- pine-script - 如何克服 Pine Script 中的“编译的脚本代码太长”
- linux - 在 Cron 作业中,GET、PHP 和 cURL 有什么区别
- r - 如何在一张表中返回多个结果?
- azure - Azure DevOPS - 在分配工作项时收到通知
- java - AWS Lambda 未在层中找到共享对象文件
- c - 为什么我在 c 中的矩阵乘法代码总是给出垃圾值?(使用共享内存和fork)
- c# - 仅获取周一和周日的上周日期