Board index » delphi » Moving between DBedit fields with enter key

Moving between DBedit fields with enter key

How can I move between DBEdit fields or call some procedure with Enter
key.

Thanks for your help !

Igor Vedernjak

 

Re:Moving between DBedit fields with enter key


If I have a form FrmMain with DbEdit1, DbEdit2, etc, I enter the following
as event handler for the "onkeypress" event of each DbEdit:

procedure TFrmMain.DbEdit1Keypress(Sender: TObject; var Key: char);
begin
 if key<>chr(13) then exit;
 if sender=DbEdit1 then DbEdit2.SetFocus;
 if sender=DbEdit2 then DbEdit3.SetFocus;
 etc, etc
end;

If FrmMain has an OK button (or any other button), make sure its "default"
property is set to false, otherwise Enter activates the buttons "onclick"
event.

This works for me, maybe there are better answers?

Igor Vedernjak <me...@siol.net> wrote in article <32ECFDD3....@siol.net>...

Quote
> How can I move between DBEdit fields or call some procedure with Enter
> key.

> Thanks for your help !

> Igor Vedernjak

Re:Moving between DBedit fields with enter key


Quote
Igor Vedernjak wrote:

> How can I move between DBEdit fields or call some procedure with Enter
> key.

> Thanks for your help !

> Igor Vedernjak

procedure TForm1.FormKeyPress(Sender:Tobject;var key:Char);
begin
  if key = #13 then
     if not (activeControl is TDBGrid)
       then begin
              Key:=#0;
              Perform(WM_NEXTDLGCTL,0,0);
            end
       else if Grid1.SelectedIndex < FieldCount-1
              then Grid1.SelectedIndex:=Grid1.SelectedIndex+1
              else Grid1.SelectedIndex:=0;
end;

Set the form's KeyPreview proprety to True

Annie.

Re:Moving between DBedit fields with enter key


On Mon, 27 Jan 1997 20:11:15 +0100, Igor Vedernjak <me...@siol.net>
wrote:

Quote
>How can I move between DBEdit fields or call some procedure with Enter
>key.

>Thanks for your help !

>Igor Vedernjak

Try this :

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if Key = #13 then
  begin
    Key := #0;
    SelectNext(ActiveControl, True, True);
  end;
end;

Other Threads