Re:Move control from one cell to other cell when press "Enter" Key
Quote
On Sun, 29 Aug 1999 22:13:41 +0800, mark <a...@abc.com> wrote:
>Hi,
> I am using D4 C/S to build up a project.
> I want to ask a question. In my project, It contain a Form and a
>StringGrid attach on it. I activiate one cell and input some charactors
>in the cell. When i press enter, it will not move to the next cell ...
>How can i move to next cell, or other cell inside the grid ??
> I need someone help, and it is urgent ..... Pls Help
>Mark
Here's the item for a Borland tech tip:
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;
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.
Steve F (Team B)