954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

DataGridView

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

}
}

faranak
Newbie Poster
13 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

you maybe select another control!!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

No, I want to use this control

faranak
Newbie Poster
13 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

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

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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

Exelio
Junior Poster in Training
57 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

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.

JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You