@ankit goel , you could try the following code to delete blank row and move the focus to next control.
private void Form1_Load(object sender, EventArgs e)
{
DataTable table=new DataTable();
table.Columns.Add("Name");
table.Columns.Add("Age");
table.Columns.Add("Id");
table.Rows.Add("test1", 22, 1001);
table.Rows.Add("test2", 22, 1002);
table.Rows.Add("test3", 22, 1003);
dataGridView1.DataSource = table;
dataGridView1.AllowUserToAddRows = false;
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
//e.SuppressKeyPress = true;
int iColumn = dataGridView1.CurrentCell.ColumnIndex;
int iRow = dataGridView1.CurrentCell.RowIndex;
if (e.KeyCode == Keys.Enter)
{
//to check if the pointer reach last column
if (iColumn == dataGridView1.ColumnCount - 1&&iRow== dataGridView1.RowCount - 1)
{
//executing when line ends
e.Handled = true;
this.SelectNextControl((Control)sender, true, true, true, true);
}
}
}
Based on my test, it works well.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.