首页 > Windows开发 > 详细

在datagridview控件中按Enter键时,将焦点设置为下一个单元格(Set focus to next cell when pressing enter key in datagridview control)

时间:2021-01-26 15:34:51      阅读:28      评论:0      收藏:0      [点我收藏+]
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];

            }
        }

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];

}
}

在datagridview控件中按Enter键时,将焦点设置为下一个单元格(Set focus to next cell when pressing enter key in datagridview control)

原文:https://www.cnblogs.com/skynight/p/14330459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!