您的位置:首页 > 其它

How can I delete the row in TStringGrid component?

2009-05-07 15:31 351 查看
From: http://www.delphi3000.com/articles/article_819.asp?SK=

If you worked with TStringGrid component, then you saw that in this component the Borland developers not provided the method for row deleting.

In this tip I describe the few ways for it:

{ 1. navigate by rows and copy the row contains to the prev row: }

procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer);

var i, j: Integer;

begin

with yourStringGrid do

begin

for i := ARow to RowCount-2 do

for j := 0 to ColCount-1 do

Cells[j, i] := Cells[j, i+1];

RowCount := RowCount - 1

end;

end;

{ 2. the modificated #1: }

procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer);

var i: Integer;

begin

with yourStringGrid do

begin

for i := ARow to RowCount-2 do

Rows[i].Assign(Rows[i+1]);

RowCount := RowCount - 1

end;

end;

{ 3. the "hacked" way. The TCustomGrid type (the TStringGrid is TCustomGrid's successor) have the DeleteRow method. But this method allocated not in public section but in protected section. So the all successors can "see" this DeleteRow method. }

type

THackStringGrid = class(TStringGrid);

procedure DeleteRow(yourStringGrid: TStringGrid; ARow: Integer);

begin

with THackStringGrid(yourStringGrid) do

DeleteRow(ARow);

end;

Personally I use the third method but the first and second are more visual.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: