2007. április 24., kedd

How to tab between fields displayed in a TDBGrid


Problem/Question/Abstract:

Inside a DBGrid I would like to tab to the next field on each line (record) in the DBGrid, but when I tab the focus jumps to the last record. How do I get this to work right? Visible fields: LineNo, Code, Qty, Description, Price, Taxable, Extended (price). I want to tab to each or at least from Code to Qty to Price.

Answer:

procedure TYourForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then { if it's an enter key }
    if not (ActiveControl is TDBGrid) then { if not on a TDBGrid }
    begin
      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;

Nincsenek megjegyzések:

Megjegyzés küldése