Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1305
  • Last Modified:

DBGrid and key press

If you press  the down/up arrow key, then the selected row will scroll down/up so long how much you press the key .

I wish to scroll just on time for each key press . If I keep pressed the down button then I wish to go to the next record and then stop untill I will press again the key .

How to do that ?
0
ginsonic
Asked:
ginsonic
  • 3
1 Solution
 
CrazyOneCommented:
Something like this might work.

var
  bKeyUp: Boolean = True;

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

  if (Key = VK_DOWN) then begin
    if bKeyUp then
      bKeyUp := False
    else
      Key := 0;
  end;

end;

procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

  bKeyUp := True;

end;


The Crazy One
0
 
CrazyOneCommented:
Actually I forgot the KeyUp part of the equtation

var
  bKeyUp: Boolean = True;

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

  if Key in [VK_DOWN, VK_UP] then begin
    if bKeyUp then
      bKeyUp := False
    else
      Key := 0;
  end;

end;

procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

  bKeyUp := True;

end;
0
 
ginsonicAuthor Commented:
Thanks for help.
0
 
CrazyOneCommented:
Glad to have been able to help. :>)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now