1

I have a number of TStringGrid components in a Form. I want to move between the StringGrids using tab.

The problem is that when the goTabs is activated, then it nicely moves between the cells of the StringGrid , but as soon as the bottom right cell is selected, the next tab hit will select the upper left cell of the same StringGrid .

How can I override this?

thanks.

Spymag
  • 105
  • 1
  • 9
  • 2
    That's not going to be a fun UI for your user. To me TAB should move between controls, or between cells in your grid, but not both. You really want your user to TAB through all the cells in one control just to get to the next control. Tabbing within a grid works for spreadsheet programs when there is a single dominant grid. – David Heffernan Feb 27 '17 at 16:58
  • Also, if you really really insist on tabbing forward like this, keep in mind you will need to implement reverse tabs too. – Jerry Dodge Feb 27 '17 at 17:19
  • Yes, I do want to do this. Its also like having a lot of editboxes and you just tab from one to another, so I dont find it so unpleasant or non intuitive. Any ideas on how to implement it? – Spymag Feb 27 '17 at 17:23
  • What happens when you have a grid with hundreds of cells? – David Heffernan Feb 27 '17 at 17:58
  • Anyway, it's easy enough to work this out. You make your own grid descendent. Then you override the `KeyDown` method. Then you change the behaviour when you are at the bottom right cell (or top left is `ssShift in Shift`) – David Heffernan Feb 27 '17 at 18:01
  • @DavidHeffernan, in this specific application I know it will be a finite number of cells. So that wont be a problem. I will consider your remarks for future apps thought!. – Spymag Feb 27 '17 at 18:57

1 Answers1

1

Something like that then! thanks all.

procedure TfrChild.Grd0KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_TAB) and (Grd0.row = Grd0.RowCount - 1) and
    (Grd0.col = Grd0.ColCount - 1) then
  begin
    Grd1.row := 1;
    Grd1.col := 0;
    Grd1.SetFocus;
  end;

end;
Spymag
  • 105
  • 1
  • 9