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

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)

上一篇:【wpf】命名空间“aaa”中不存在“bbb”名称的解决方法


下一篇:delphi lazarus dll静态调用