如何快速获得DBGrid或TDataSet上一条数据的值?(100分)

  • 主题发起人 主题发起人 netrobo
  • 开始时间 开始时间
N

netrobo

Unregistered / Unconfirmed
GUEST, unregistred user!
问题如标题所述,实现此功能的目的主要是因为要求本行数据根据上一行数据所得来。
 
取上一行数据比较麻烦,试试Dataset.Fieldvalues,但你要事先知道行号。
 
DataSet.Previous;
 
想在不改变当前行的前提下获得上一行的值。
 
你看可以通過書簽來實現行嗎?
 
先 DataSet.Previous;
读取数据
然后 DataSet.Next;
 
定义一个STRINGLIST。在INSERT之前把如有的字段数据写入,然后在读出就行。不知成不
 
用dxgrid可以做到,用的ANode对象来取
 
IsCellSelected(这是我的程序里用到的一个方法,可以在鼠标单击的时候来调用,可以快速知道行号
能满足要求了吧,如果能请给我200分,谢谢!
function IsCellSelected(StringGrid : TStringGrid; X, Y : LONGINT): BOOLEAN;
begin
Result := false;
try
if (X >= StringGrid.Selection.Left) and (X <= StringGrid.Selection.Right) and (Y >= StringGrid.Selection.Top) and (Y <= StringGrid.Selection.Bottom)
then
Result := true;
except
end;
end;
例子:
for x:= 1 to stgd_detail.rowcount do
begin
if IsCellSelected(stgd_detail,0,x) then
showmessage(stgd_detail.cells[0,x]);//得到选中行的第0个数据
break;
end;
 
多人接受答案了。
 
后退
顶部