[Solved] TStringGrid with AutoAdvance:= aaDown. lazarus / 31-LCL ---------------------------------------------------------------------- Avishai · 2011-08-01 15:53 I have a TStringGrid with AutoAdvance:= aaDown.  When the user is in the bottom row of a Column that is not the last column, What I want is for Tab, Return or Down-Key to go to the Top Row of the next Column.  I have code that does this, but it only works if the user does not type anything in the bottom cell.  If they do, the focus goes to the next control instead of advancing the way I described. The code does execute, but it seems to be ignored.  Any ideas? procedure TForm1.sgAvarKeyDown(Sender: TObject; var Key: Word;   Shift: TShiftState); begin   with Sender as TstringGrid do begin     if (Col < ColCount-1) and (Row = RowCount-1) then begin       if Key in [VK_Tab,VK_RETURN,VK_DOWN] then begin         Col:= Col+1;         Row:= FixedRows;         Key:= 0;       end;     end;   end; end; ---------------------------------------------------------------------- Avishai · 2011-08-08 12:53 YES!  I finally got it! procedure aaDownWrap(Sender: TObject; var Key: Word); var   ParentForm: TCustomForm;   Flag: Boolean;   I: Integer; begin   with Sender as TStringGrid do begin     if Key <> VK_Tab then exit;     Flag:= False;     if (Row = RowCount-1)and(Key = VK_Tab) then begin       Flag:= (Col = ColCount-1)and(Row = RowCount-1);       Col:= Col+1;       Row:= FixedRows;       Key:= 0;     end;     ParentForm:= GetParentForm(Sender as TStringGrid);     if Flag then begin       Row:= FixedRows;       Col:= FixedCols;       I:= TabOrder+1;       if I = ParentForm.ControlCount then         I:= 0;       ParentForm.FocusControl(ParentForm.Controls/[I/] as TWinControl);     end else       if Not Flag then         SetFocus;   end; end; procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;   Shift: TShiftState); begin   with Sender as TStringGrid do begin     case AutoAdvance of       aaDown: aaDownWrap(Sender, Key);     end;   end; end; ---------------------------------------------------------------------- Avishai · 2011-08-08 15:51 This code is only partly complete.  I still have work to do.  Shift- Tab... ---------------------------------------------------------------------- BigChimp · 2011-08-08 16:01 Keep at it, Avishai - just wishing you good luck. Can be very frustrated to figure this kind of thing out.. ---------------------------------------------------------------------- Avishai · 2011-08-08 16:06 Yes, it can be very frustrating at times, but you almost always learn new things in the process.  Things you might not find any other way.  For example,  ParentForm:= GetParentForm(Sender as TStringGrid); I wouldn't have found this otherwise and it allows me to do a lot of things in a very generic way.