如何在 TStringGrid 刪除一列的答案, 終於找到了!! |
|
yu168
一般會員 發表:29 回覆:27 積分:16 註冊:2002-06-28 發送簡訊給我 |
來源出處:http://www.scalabium.com/faq/dct0057.htm
為了怕文章連結不見了, 我將內容貼上來, 希望不會侵犯到作者的著作權
大家參考參考!! 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. --------------------------------------------------------------------------------
Copyright© 1998-2003, Scalabium. All rights reserved.
webmaster@scalabium.com
January 4, 2000
發表人 - ddy 於 2003/04/25 19:10:42
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |