Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TStringGrid: How To Insert Row

1,184 views
Skip to first unread message

Wayne Niddery (TeamB)

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
Michael Fullerton wrote in message <36ba4806...@forums.borland.com>...
>I want to insert a row in a TStringGrid. A post in Deja News
>indicated this would work:
>
>type
> TGridCracker = Class( TCustomGrid )
> End;


Don't need the above End, this is enough:
TGridCracker = Class( TCustomGrid );

You're on the right track but there is no InsertRow method at all. You need
to add a row, then move it.

procedure TForm1.Button1Click(Sender: TObject);
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
TGridCracker(StringGrid1).MoveRow(StringGrid1.RowCount - 1,
StringGrid1.Row);
StringGrid1.Row := StringGrid1.Row - 1;
StringGrid1.SetFocus;
end;

--
Wayne Niddery - WinWright Consulting
Delphi, C++Builder, JBuilder, InterDev --
http://home.ican.net/~wniddery/RADBooks.html
...remove chaff when replying...
"You know you've landed gear-up when it takes full power to taxi"

Michael Fullerton

unread,
Feb 5, 1999, 3:00:00 AM2/5/99
to
I want to insert a row in a TStringGrid. A post in Deja News
indicated this would work:

type
TGridCracker = Class( TCustomGrid )
End;

...
TGridCracker.InsertRow(StringGrid1.Row);

but I get an Undeclared Identifier error.

I'd rather not use another 3rd party grid control.

___
Michael E. Fullerton | The Delphi Compendium
http://www.cyber-matrix.com/delphi.htm

Alexandra

unread,
Mar 4, 1999, 3:00:00 AM3/4/99
to
I had the same problem. What I did : created a new decendent and
override coiple methods
procedure DeleteRow(ARow: Longint);
procedure DeleteColumn(ACol: Longint);
procedure MoveColumn(FromIndex, ToIndex: Longint);
procedure MoveRow(FromIndex, ToIndex: Longint);
procedure BeginUpdate;//stop paint
procedure EndUpdate;//start paint again
published
{ Published declarations }
property InplaceEditor;
end;

procedure Register;

implementation

procedure TNohauGrid.DeleteRow(ARow: Longint);
begin
inherited DeleteRow(ARow);
end;

procedure TNohauGrid.DeleteColumn(ACol: Longint);
begin
inherited DeleteColumn(ACol);
end;

procedure TNohauGrid.MoveColumn(FromIndex, ToIndex: Longint);
begin
inherited MoveColumn(FromIndex, ToIndex);
end;

procedure TNohauGrid.MoveRow(FromIndex, ToIndex: Longint);
begin
inherited MoveRow(FromIndex, ToIndex);
end;

So, for insert you can increase Rowcount and move row to place;

Eddie Shipman

unread,
Mar 5, 1999, 3:00:00 AM3/5/99
to
Here is a way to insert a row:
procedure InsertRows(RowIndex, RCount : LongInt);
var
i: LongInt;
begin
RowCount := RowCount + RCount;
for i := RowCount - 1 downto RowIndex do Rows[i] := Rows[i - RCount];
end;

and remove rows:
procedure RemoveRows(RowIndex, RCount : LongInt);
var
i: LongInt;
begin
for i := RowIndex to RowCount - 1 do Rows[i] := Rows[i + RCount];
RowCount := RowCount - RCount;
end;

0 new messages