hi
i have created one UI application using c#. i want to use PageDown Keys for navigate between rows, but when i press PageDown keys datagridview select last row.
How can i do this?
thanks in advance
my code:

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.PageDown)
            {
                int cRow=dataGridView1.CurrentRow.Index;
                cRow += 1;
                dataGridView1.CurrentCell = dataGridView1.Rows[cRow].Cells[0];

            }
        }

Edited 3 Years Ago by happygeek: fixed formatting

hi,

try using the SelectionChanged event of the datagridview. you can use arrow keys to navigate through the records and this event gets fired automatically.


Hope this helps.


Regards

Exelio

I assume what you want to do is trap the Page Down key and use it for navigating the datagridview. The problem in your code is that you are not telling the datagridview that you have aleady handle the key press.

Let it know that you have taken care of the key press by setting the Handled property to true.

If using KeyPress then assign the KeyPressEventArgs e ... e.Handled = true;
if using KeyDown then assign the KeyEventArgs e ... e.handled = true;

This prevents the event from going into the internal key event handler of the DataGridView.

This article has been dead for over six months. Start a new discussion instead.