在datagridview控件中按Enter键时,将焦点设置为下一个单元格 [英] Set focus to next cell when pressing enter key in datagridview control
本文介绍了在datagridview控件中按Enter键时,将焦点设置为下一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的窗口应用程序中使用了datagridview控件。
当按下单元格中的输入键时,我需要关注下一个单元格。
In my window application datagridview control used .
I need to focus next cell when press enter key in a cell.
推荐答案
在这里,看看前面提到的同一个问题的答案:使输入键作为文本框上的Tab键 [ ^ ] - Solution1适用于Winforms,Solution2适用于Webforms。
Here, have a look at answer to same question asked earlier: make enter key act as Tab key on Textbox[^] - Solution1 is for Winforms and Solution2 is for Webforms.
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
int iColumn = dataGridView1.CurrentCell.ColumnIndex;
int iRow = dataGridView1.CurrentCell.RowIndex;
if (iColumn == dataGridView1.Columns.Count - 1)
dataGridView1.CurrentCell = dataGridView1[0, iRow + 1];
else
dataGridView1.CurrentCell = dataGridView1[iColumn + 1, iRow];
}
}
使用此javascript函数,按下回车键时将关注下一个输入控件。< br $>
Use this javascript function, it will focus on next input control on pressing enter key.
<script type="text/javascript">
这篇关于在datagridview控件中按Enter键时,将焦点设置为下一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文