How to tab between fields displayed in a TDBGrid (Views: 100)


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.


procedure TYourForm.FormKeyPress(Sender: TObject; var Key: Char);
  if Key = #13 then { if it's an enter key }
    if not (ActiveControl is TDBGrid) then { if not on a TDBGrid }
      Key := #0; { eat enter key }
      Perform(WM_NEXTDLGCTL, 0, 0); { move to next control }
    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
          selectedindex := 0;

<< Back to main page