views:

212

answers:

3

When I press CTRL and Up Arrow on DataGridView I go to the first row. When I do the same with Down Arrow I go to last row in DGV. How to disable this behavior in this direction that when I will do CTRL+Up I will go one row up and when I do CTRL+Down I go one row down?

A: 

look into overriding the OnKeyPress event... You may have to declare your own class not exact, but a start...

public class MyDataGridView : DataGridView
{
   ...
   ...

   public override void OnKeyPress( object sender, KeypressEventArgs e )
   {
      trap your own "e." values
   }
}
DRapp
A: 

You should not override OnKeyPress () because the navigation handlers eat navigation keystrokes before they're sent to OnKeyPress ().

Instead, you should override ProcessDialogKey () and/or ProcessDataGridViewKey (), which exist explicitly to handle navigation.

ProcessDialogKey

ProcessDataGridViewKey


ETA: with all due respect, in general it's usually not a particularly good idea to change navigation behavior. A lot of applications use DataGridView, and users typically expect the default behavior, because that's what most applications will use. There are exceptions and sometimes good reasons to change the default navigation, but just because you personally don't like the default behavior is usually not a sufficient reason to change it. This is, of course, just my personal opinion; YMMV.

XXXXX
A: 

You need to override ProcessDialogKey and 'cancel' the event if you detect a certain key or key combination.

0A0D