StringGrid中动态增加一行怎么做? stringgrid中随便在某行中增加一行,并且原有的数据不丢失,我的数据不是数据库中的数据。就象是在Excel表格一样中右键选增加一行就增加了一行并且原来的数据会自动向下移动 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 StringGrid1->RowCount++;int i=StringGrid1->Row;for(int j=StringGrid1->Row-1;j>=i;j--) //循环复制内容,然后再把那行清空 太麻烦,建议用DevExpress.SpreadSheet 控件,和EXCEL几乎一模一样。很多地方可以下,搜索一下 好简单,我做过,分数全部给我啦.........var i: Integer; //先增加一行 sgWords.RowCount := sgWords.RowCount + 1; sgWords.Rows[sgWords.RowCount - 1].Clear; //移形换位,把最后一行跟你指定的行换位置! CurrentRow := sgWords.Row; for i := sgWords.RowCount - 1 downto CurrentRow + 1 do begin sgWords.Rows[i].Assign(sgWords.Rows[i - 1]); end; sgWords.Rows[CurrentRow].Clear; sgWords.Row := CurrentRow; SendMessage(sgWords.Handle, EM_SCROLLCARET, 0, 0);//多送你一个方法:滚动到插入行的位置 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, Grids;type TForm1 = class(TForm) StringGrid1: TStringGrid; BitBtn1: TBitBtn; procedure FormCreate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;type tgridex = class(TStringGrid)end;var Form1: TForm1;implementation{$R *.dfm}// ToIndex是你要在strgrid插入行的INDEXprocedure stringgridadd(strgrid:TStringGrid;ToIndex:integer);begin strgrid.RowCount:=strgrid.RowCount+1; tgridex(strgrid).MoveRow(strgrid.RowCount,ToIndex+1);end;procedure TForm1.FormCreate(Sender: TObject);var i,j:integer;begin StringGrid1.RowCount:=12; StringGrid1.ColCount:=12; StringGrid1.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goRowSelect]; for i:=1 to 10 do begin for j:=1 to 10 do begin StringGrid1.Cells[j,i]:=Format('%d,%d',[i,j]); end; end;end;procedure TForm1.BitBtn1Click(Sender: TObject);begin stringgridadd(StringGrid1,1); //在第一行后插入end;end. wanbb (wanbb) ,刚测试通过。 16进制发送问题 怎么判断我修改了哪个记录? 如何用类的成员函数做回调函数呀? 求D8和D7的补丁 请问高手:如何edit的获得当前输入法,及设定edit当前输入法 一个关于WIN98关机效果的问题?您感兴趣吗?您知道吗?进来说说看。。 关于Foxpro的处理 通过了国家高级程序员考试,主要学pb,delphi在上海薪金可拿多少? 请问如何把Canvas中的图片存储下来? 2001年微软收购BORLAND之行 我用Quickreport做的報表現在出現這樣一個問題,在memo中,在98下面和2000下面字的行距不一樣,如果解決。 如何控制显示
int i=StringGrid1->Row;
for(int j=StringGrid1->Row-1;j>=i;j--)
//循环复制内容,然后再把那行清空
var
i: Integer;
//先增加一行
sgWords.RowCount := sgWords.RowCount + 1;
sgWords.Rows[sgWords.RowCount - 1].Clear;
//移形换位,把最后一行跟你指定的行换位置!
CurrentRow := sgWords.Row;
for i := sgWords.RowCount - 1 downto CurrentRow + 1 do
begin
sgWords.Rows[i].Assign(sgWords.Rows[i - 1]);
end;
sgWords.Rows[CurrentRow].Clear;
sgWords.Row := CurrentRow;
SendMessage(sgWords.Handle, EM_SCROLLCARET, 0, 0);//多送你一个方法:滚动到插入行的位置
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;type tgridex = class(TStringGrid)
end;var
Form1: TForm1;
implementation{$R *.dfm}
// ToIndex是你要在strgrid插入行的INDEX
procedure stringgridadd(strgrid:TStringGrid;ToIndex:integer);
begin
strgrid.RowCount:=strgrid.RowCount+1;
tgridex(strgrid).MoveRow(strgrid.RowCount,ToIndex+1);
end;procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
StringGrid1.RowCount:=12;
StringGrid1.ColCount:=12;
StringGrid1.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goRowSelect];
for i:=1 to 10 do
begin
for j:=1 to 10 do
begin
StringGrid1.Cells[j,i]:=Format('%d,%d',[i,j]);
end;
end;
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
stringgridadd(StringGrid1,1); //在第一行后插入
end;end.