2798:Making the Enter key work like a Tab in a TDBGrid
Information provided by Inprise Corporation
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
Cao
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED]
> Behalf Of Roberto Freitas
> Sent: 01 November 2005 10:38
> To: [email protected]
> Subject: [delphi-en] Making ENTER work as TAB on DBCtrlGrid
>
>
> When user presses <Enter> key I would like cursor jump to the next
> control on the form. As suggested by Paul on this site, I've got good
> tip at this link:
> http://delphi.about.com/od/vclusing/a/entertab.htm
> But it has answers only for Edit and DBGrid controls, not for
> DBCtrlGrid. Pressing <Enter> key when cursor is on DBCtrlGrid has an
> special effect to change the selection between control itself and
> current record.
> So I'm still lacking how to do it in DBCtrlGrids.
> Does anyone know how to do it?
>
>
>
>
>
>
>
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: [EMAIL PROTECTED]
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/i7folB/TM
--------------------------------------------------------------------~->
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/