关于 删除 一行 ,我见到较常见的有如下3种:(来自 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.就想问一下, 上面 3种 方式,哪种 效率最高,速度最快??(主要是 在行数很多时删除一行,需要速度的最快的方式)第3种 DeleteRow方式 的源码 看了一下,好像没在 Copy数据 ,是否快一点??Delphi源码我也没看全明白,请大家指点下!!!
或者有其他更快方式??
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.就想问一下, 上面 3种 方式,哪种 效率最高,速度最快??(主要是 在行数很多时删除一行,需要速度的最快的方式)第3种 DeleteRow方式 的源码 看了一下,好像没在 Copy数据 ,是否快一点??Delphi源码我也没看全明白,请大家指点下!!!
或者有其他更快方式??
解决方案 »
- 安装了Fast Report 报表控件,不支持XE,删除重新安装出现错误
- 来帮我看看这个完成端口的定义
- 函数返回类型为String?这样的格式如何解析?
- 如何把在DBGrid选中的多项纪录删除?急用,最好写详细点。50分相送!在线等。
- GGJJ,怎样将一个十六进制赋给一个byte 或者 word呀!请教!谢谢!
- 一个三层的程序,db:oralce, 客户端clientdataset在进行filter汉字时,总是报错EDBClient with message"type mismatch in expression"
- 显示桌面怎么找回来?
- 怎么把一个数据表里的image字段内容赋到另一个表 的image字段,谢谢了,
- ★关于windows xp的中文字体问题!比win98中少很多,程序界面的文字变形了,怎么办?
- 不懂!怎样和程序一起发布BDE,是直接把那些dll文件考过去吗?请各位详细指点一下
- 已获得进程PID,如何获取该进程某dll的全路径
- 请教一个关于流播放里TBCMemFileStream的问题
1需要的时间最长
数据量不大,应该无所谓,呵呵
cds和dbgrid 一句delete就行了前提是不要执行ApplyUpdates
是这样的吗?是的话就准备结贴了。
用 ClientDataSet + DBGrid 之后,我在查找数据时(比如,查找 某行第二列 的值 等于 X),
当 查找下一条数据时(即 “ClientDataSet1.MoveBy(1)”),光标会动,DBGrid画面也在动(即:一条一条往下走)。
如何能让 DBGrid 的画面不动啊??(就像在操作StringGrid一样??)
ClientDataSet1.EnableControls; //恢复