嗯,我有个关于n00b的问题。我已经在网上冲浪和类似的问题,但没有找到任何正确的答案,如此简单(如我所想)的问题。
我有一台DBGrid。我选择了一行,并对链接到该行的另一个数据执行了一些操作。完成后,正在刷新的DBGrid和选中的行重置为first。我希望在刷新DBGrid数据之前选择与所选行相同的行。有什么建议吗?
发布于 2009-10-25 19:30:59
在刷新之前,将链接数据集的当前选择保存为书签,然后恢复书签。
发布于 2014-07-27 17:02:28
这个答案是梅森的一个小补充,而不是一个替代方案。我之所以添加它,只是因为出现了另一个答案,错误地建议使用数据集的RecNo属性。并不是所有的TDataSet后代都能可靠地或者根本不实现RecNo。一些子代只返回一个常量值,比如当前行的RecNo为0,当你给它赋值时什么也不做。
procedure TMyForm.DoSomethingWithDataSet(ADataSet : TDataSet);
var
Bookmark : TBookmark;
begin
Bookmark := ADataSet.GetBookmark; // Save your place in ADataSet
try
Screen.Cursor := crSqlWait; // Show the user that something is happening
Update; // update the form to make sure screen cursor updates
ADataSet.DisableControls;
// do something with ADataSet here e.g.
ADataSet.First;
while not ADataSet.Eof do begin
// do something with current row here, then
ADataSet.Next;
end;
finally
ADataSet.GotoBookmark(Bookmark); // Return to where you were at outset
ADataSet.FreeBookmark(Bookmark);
ADataSet.EnableControls;
Screen.Cursor := crDefault; // Let the user see you're done
end;
end;发布于 2014-07-27 08:23:05
RecKey:=DmFRM.ViewTBL.RecNo;
with DmFRM.ViewTBL do
begin
Active:=false;
Active:=True;
RecNo:=RecKey;
end;https://stackoverflow.com/questions/1620644
复制相似问题