Insert a row in a TStringGrid at a certain position (Views: 101)


Is there a method to insert a row into a StringGrid or do I have to shuffle all higher rows up 1?


TCustomGrid has a very useful but unfortunately protected method named MoveRow. You can get at it using the cracker class strategy:

  TGridCracker = class(TCustomGrid);

{insert a line at row 5}
stringgrid1.rowcount := stringgrid1.rowcount + 1;
TGridCracker(stringgrid1).Moverow(stringgrid1.rowcount - 1, 5);

You first add a new empty line, then move it to the required position. This automatically moves all following lines one position down.

<< Back to main page