Technical Information Database TI737D.txt Making the Enter key work like a Tab in a TDBGrid Category :VCL Platform :All Product :Delphi All Description: Code to make thekey act as the tab key while inside a grid. This code also includes the processing of the 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 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; Reference: 7/16/98 4:33:53 PM
Last Modified: 01-SEP-99