怎样使用代码移动StringGrid的行?上移下移或者删除,最后是无缝的。
解决方案 »
- 数据库的数据类型
- 〓如何对TQUERY控件的SELECT结果再进行第二次查询
- 急!急!就要下岗!求股票K线图代码!!!,
- olecontainer 里的word内容如何复制到粘贴板?????????
- 大家看看这样的查询问题能解决吗?
- 请问在TreeView怎样给根节点和节点和子节点分别添加上不同的图标。最好有实例。
- PageControl1改变颜色的最简单方法是?
- 各位齊天大聖。。。看吧。
- 我做了个类似SQL server服务管理的小东东,机器启动后倒是能出现在托盘里,但是任务栏中也有。请问我如何把任务栏中的应用程序图标去掉,
- 有一些新的api及其用到的常数(如:产生Balloon Tooltips用到的tts_balloon)在delphi中没有定义,这些常数的值为多少到哪里去查呢?(MS
- 局域网使用dbf处理数据,有时出现数据保存丢失,请教高手!送1000分
- 如何获得机器的硬盘和光盘序列号?
var
s: TStrings;
i: Integer;
begin
i := sg.Row;
if i <=1 then Exit;
s := TStringList.Create;
s.Assign(sg.Rows[i-1]);
sg.Rows[i-1] := sg.Rows[i];
sg.Rows[i] := s;
sg.Row := i-1;
s.Free;
end;procedure TForm1.Button2Click(Sender: TObject); {下移}
var
s: TStrings;
i: Integer;
begin
i := sg.Row;
if i >= sg.RowCount-1 then Exit;
s := TStringList.Create;
s.Assign(sg.Rows[i+1]);
sg.Rows[i+1] := sg.Rows[i];
sg.Rows[i] := s;
sg.Row := i+1;
s.Free;
end;procedure TForm1.Button3Click(Sender: TObject); {删除}
var
i: Integer;
begin
for i := sg.Row to sg.RowCount - 1 do
sg.Rows[i] := sg.Rows[i + 1];
sg.RowCount := sg.RowCount - 1;
end;
{
编号:
函数名: gvStrGridMove(sg: TStringGrid; FromIndex,ToIndex: Integer);
文件名: PubFunUnit.pas
入口参数: sg:目标StringGrid
FromIndex: 源记录索引
ToIndex:目的记录索引
出口参数:
引用全局变量:
修改全局变量:
父函数:
子函数:
引用数据:
函数功能: 在StringGrid中移动一条记录
}
procedure gvStrGridMove(sg: TStringGrid; FromIndex,ToIndex: Integer);
var
lst:TStringList;
i,id,x:integer;
begin
lst :=TStringList.Create;
id:=ToIndex; // 目标指针
if FromIndex>=ToIndex then x:=1 else x:=-1; // 判断指针下移还上移
with sg do
begin
while id<>FromIndex do
begin
lst.clear;
for i:=0 to ColCount-1 do
lst.Add(Cells[i,id]);
for i:=0 to ColCount-1 do
Cells[i,id] :=Cells[i,FromIndex];
for i:=0 to ColCount-1 do
Cells[i,FromIndex] :=lst.Strings[i];
id :=id+x; // 指针转移 (x=-1 or x=1)
end;
end;
FreeAndNil(lst);
end;{
编号:
函数名: procedure gvStrGridDel(sg: TStringGrid; id: integer;iDelRows: integer);
文件名: PubFunUnit.pas
入口参数: sg:目标StringGrid
FromIndex: 源记录索引
出口参数:
引用全局变量:
修改全局变量:
父函数:
子函数:
引用数据:
函数功能: 在StringGrid中删除iDelRows条记录
}
procedure gvStrGridDel(sg: TStringGrid; id: integer;iDelRows: integer);
var
iRow,iCol:integer;
begin
if iDelRows < 1 then
exit; if id < 1 then
exit; with sg do
begin
for iRow := id to RowCount-1-iDelRows do
for iCol :=0 to ColCount-1 do
Cells[iCol,iRow] := Cells[iCol,iRow + iDelRows]; if (RowCount - iDelRows) > 1 then
RowCount := RowCount - iDelRows
else
begin
RowCount := 2;
sg.Rows[1].Text := '';
end;
end;
end;{
编号:
函数名: procedure gvStrGridClear(sg: TStringGrid);
文件名: PubFunUnit.pas
入口参数: sg:目标StringGrid
出口参数:
引用全局变量:
修改全局变量:
父函数:
子函数:
引用数据:
函数功能: 在StringGrid中删除所有记录
}
procedure gvStrGridClear(sg: TStringGrid);
var
iTmp: integer;
begin
sg.RowCount := 2;
sg.Rows[1].Text := '';
sg.Row := 1;
end;