You are on page 1of 2

Example Delphi - http://exampledelphi.

com

Delete Row in TStringGrid Component 2008-04-25 12:00:01


admin
//When we work with TStringGrid Component, There is no methode for deleting row //This is how we can Delete row in TStringGrid Component //Just place Button1 (TButton) and StringGrid1 (TStringGrid) on the Form1 then try this code unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} //Procedure Below to fill StringGrid1 Cells with its coordinate self procedure TForm1.FormCreate(Sender: TObject); var i,j:integer; begin for i := 0 to StringGrid1.RowCount -1 do begin for j := 0 to StringGrid1.ColCount - 1 do begin StringGrid1.Cells[j,i] := IntToStr(j)+','+IntToStr(i); end; end; end; //Copy the parameterized row contains from next row procedure DeleteStringGridRow1(AStringGrid:TStringGrid;Arow:Integer); var

Post url: http://exampledelphi.com/delphi.php/tips-and-tricks/delete-row-in-tstringgrid-component/ - Copyright admin - Page 1

Example Delphi - http://exampledelphi.com

i,j:integer; begin for i := Arow to AStringGrid.RowCount - 2 do begin for j := 0 to AStringGrid.ColCount - 1 do begin AStringGrid.Cells[j,i] := AStringGrid.Cells[j,i+1]; end; end; AStringGrid.RowCount := AStringGrid.RowCount-1; end; procedure TForm1.Button1Click(Sender: TObject); var SelectedRow:integer; begin //Click to the row you want to delete SelectedRow := StringGrid1.Row; DeleteStringGridRow1(StringGrid1,SelectedRow); end; end.

Post url: http://exampledelphi.com/delphi.php/tips-and-tricks/delete-row-in-tstringgrid-component/ - Copyright admin - Page 2

You might also like