728x90

Key_Down 이벤트에 아래와 같이 코드를 추가해주면 엔터키를 쳤을 때 다음 행으로 이동이 안된다.

구글에서 c# datagridview cell enter event 로 검색하면 관련 게시글들이 나온다.


private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
    {
        int column = dataGridView1.CurrentCell.ColumnIndex;
        int row = dataGridView1.CurrentCell.RowIndex;
        dataGridView1.CurrentCell = dataGridView1[column, row];
        e.Handled = true;
    }
}


엔터키를 치면 행으로 이동하지 않고 칼럼으로 이동하고 마지막 칼럼에서는 다음행의 첫번째 칼럼으로 이동하게 하는 코드

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
    {
        e.SuppressKeyPress = true;
        int column = dataGridView1.CurrentCell.ColumnIndex;
        int row = dataGridView1.CurrentCell.RowIndex;
        if (column == dataGridView1.Columns.Count -1)
        {
            dataGridView1.CurrentCell = dataGridView1[0, row + 1];
        }
        else
        {
            dataGridView1.CurrentCell = dataGridView1[column + 1, row];
        }
    }
}

블로그 이미지

Link2Me

,