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];

            }
        }

you maybe select another control!!

No, I want to use this control

I mean do u sure the gridview is selected in other meaning the focused control

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.