Board index » delphi » How to make ENTER like TAB?

How to make ENTER like TAB?

In article: <3vpgs2$...@tribune.usask.ca>  carl...@crocus.sasknet.sk.ca (Carlton Comp. High School) writes:
Quote

> In a TDBGrid I am currently working on, I would like the ENTER key to act
> as the TAB key (because the table is all numbers, and the user will be
> doing most of the data entry from the numeric keypad, and would like to
> hit the enter key after each cell is complete, moving to the next cell in
> the row).  So far I haven't had any luck trying to do this with
> OnKeyUp/Down.  Any suggestions?

> David Dice              carl...@crocus.sasknet.sk.ca

The following code was posted a little while ago...

Quote
>   How do I make the [ENTER] key work like the [TAB] key in a DBGrid?

It's so easy... Just define THREE events for DBGrid:

Insert next line into OnKeyDown & OnKeyUp method:

         if (Shift=[]) and (Key = VK_RETURN) then Key :=VK_TAB;

And another line into OnKeyPress:

         if Key=#13 then Key:=#9;

Warning: Have'nt tried it myself so I can't verify that it
         works.

Regards from Ian.
--
                     ||||||||
                     | ~  ~ |
                    (| @  @ |)
----------------oOOo---(__)---oOOo------------------------
| Ian - "Smoke me a kipper I'll be back for breakfast !" |
|                                                        |
| EMail IanMa...@breallon.demon.co.uk    Banco Real s.a. |
|                                        (London Branch) |
----------------------------------------------------------

 

Re:How to make ENTER like TAB?


In a TDBGrid I am currently working on, I would like the ENTER key to act
as the TAB key (because the table is all numbers, and the user will be
doing most of the data entry from the numeric keypad, and would like to
hit the enter key after each cell is complete, moving to the next cell in
the row).  So far I haven't had any luck trying to do this with
OnKeyUp/Down.  Any suggestions?

David Dice              carl...@crocus.sasknet.sk.ca

Re:How to make ENTER like TAB?


In article <3vpgs2$...@tribune.usask.ca>, carl...@crocus.sasknet.sk.ca
says...
Quote

>In a TDBGrid I am currently working on, I would like the ENTER key to act
>as the TAB key (because the table is all numbers, and the user will be
>doing most of the data entry from the numeric keypad, and would like to
>hit the enter key after each cell is complete, moving to the next cell in
>the row).  So far I haven't had any luck trying to do this with
>OnKeyUp/Down.  Any suggestions?

The following does work. It is extracted from borland's TI2788

Code to make the <Enter>key act as the tab key while inside a grid.

This code also includes the processing of the <Enter> key for the entire
application - including fields, etc.  The grid part is handled in the
ELSE portion of the code.  The provided code does not mimic the behavior
of the <Tab> key stepping down to the next record when it reaches the last
column in the grid - it moves back to the first column - .

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
{ This is the event handler for the FORM's OnKeyPress event! }
{ You should also set the Form's KeyPreview property to True }
begin
  if Key = #13 then                              { if it's an enter key }
    if not (ActiveControl is TDBGrid) then begin { if not on a TDBGrid }
      Key := #0;                                 { eat enter key }
      Perform(WM_NEXTDLGCTL, 0, 0);              { move to next control }
    end
    else if (ActiveControl is TDBGrid) then      { if it is a TDBGrid }
      with TDBGrid(ActiveControl) do
        if selectedindex < (fieldcount -1) then  { increment the field }
          selectedindex := selectedindex +1
        else
          selectedindex := 0;
end;

Hope this helps:

Farley
car...@idirect.com

Other Threads