Delphi - restore actual row in DBGrid

Posted by durumdara on Stack Overflow See other posts from Stack Overflow or by durumdara
Published on 2010-06-08T08:12:05Z Indexed on 2010/06/08 8:32 UTC
Read the original article Hit count: 630

Filed under:
|
|
|
|

Hi!

D6 prof.

Formerly we used DBISAM and DBISAMTable. That handle the RecNo, and it is working good with modifications (Delete, edit, etc).

Now we replaced with ElevateDB, that don't handle RecNo, and many times we use Queries, not Tables.

Query must reopen to see the modifications.

But if we Reopen the Query, we need to repositioning to the last record. Locate isn't enough, because Grid is show it in another Row. This is very disturbing thing, because after the modification record is moving into another row, you hard to follow it, and users hate this.

We found this code:

function TBaseDBGrid.GetActRow: integer;
begin
 Result := -1 + Row;
end;


procedure TBasepDBGrid.SetActRow(aRow: integer);
var
 bm : TBookMark;
begin
 if IsDataSourceValid(DataSource) then with DataSource.DataSet do begin
  bm := GetBookmark;
  DisableControls;
  try
   MoveBy(-aRow);
   MoveBy(aRow);
   //GotoBookmark(bm);
  finally
   FreebookMark(bm);
   EnableControls;
  end;
 end;
end;

The original example is uses moveby. This working good with Queries, because we cannot see that Query reopened in the background, the visual control is not changed the row position.

But when we have EDBTable, or Live/Sensitive Query, the MoveBy is dangerous to use, because if somebody delete or append a new row, we can relocate into wrong record.

Then I tried to use the BookMark (see remark). But this technique isn't working, because it is show the record in another Row position...

So the question: how to force both the row position and record in DBGrid?

Or what kind of DBGrid can relocate to the record/row after the underlying DataSet refreshed?

I search for user friendly solution, I understand them, because I tried to use this jump-across DBGrid, and very bad to use, because my eyes are getting out when try to find the original record after update... :-(

Thanks for your every help, link, info: dd

© Stack Overflow or respective owner

Related posts about delphi

Related posts about dataset