Click here to Skip to main content
15,884,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to move to next control in the form on pressing of down key in datagridview??
Posted
Comments
Maddy selva 20-Feb-15 0:15am    
Have u google it?

1 solution

You will probably annoy your users by doing this but this would work
C#
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Down)
    {
        textBox1.Focus(); // Replace this with the control you want
        e.Handled = true;
    }
}

Note the use of e.Handled = true; to stop the key press being processed by the DataGridView (and focus returning to it).

I would advise checking whereabouts you are in the DGV and only move to the next control if the user is on the last row e.g.
C#
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode != Keys.Down || dataGridView1.CurrentCell.RowIndex != dataGridView1.Rows.Count - 1) return;

    textBox1.Focus();
    e.Handled = true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900