Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete data from grid except for the header row 2

Status
Not open for further replies.

Mezzzo

Technical User
May 30, 2003
56
US
Hi Group

How do I modify this code so the header row is not
deleted.
Thanks!!

procedure TfrmDrw.btnClearGridClick(Sender: TObject);
var
i: Integer;
begin
for i := 0 to StringGrid1.ColCount do
StringGrid1.Cols.Clear;
end;
 
Here is one way:
[blue]
Code:
procedure TfrmDrw.btnClearGridClick(Sender: TObject);
var
   i: Integer;
   slTemp:TStringList;
begin
   slTemp := TStringList.Create;
   try
     slTemp.Assign( StringGrid1.Rows[0] );
     for i := 0 to StringGrid1.ColCount do
        StringGrid1.Cols[i].Clear;
     StringGrid1.Rows[0].Assign( slTemp );
   finally
     slTemp.Free;
   end;  
end;
[/color]

 
Code:
procedure TfrmDrw.btnClearGridClick(Sender: TObject);
var
   i: Integer;
begin
   for i := StringGrid1.FixedRows to StringGrid1.RowCount do
      StringGrid1.Rows[i].Clear;
end;

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top