Ajeet Singh

Ajeet Singh

  • NA
  • 193
  • 18.6k

How to dataGridView cursor go to next line when press Enter

Jun 20 2018 12:28 AM
//Below Code is not working and i am not able to find the errror...... 
 
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
if (col < dataGridView1.ColumnCount - 1)
{
col++;
}
else
{
col = 1;
row++;
}
if (row == dataGridView1.RowCount)
{
dataGridView1.Rows.Add();
dataGridView1.CurrentCell = dataGridView1[col, row];
e.Handled = true;
}
}
}

Answers (1)