Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since 'MoveBy's are working for you, use them. </p> <p>Get a 'Bookmark' before closing the dataset. Do your work, reopen the dataset and then reposition your record on the grid with 'MoveBy's. When you're done, get another Bookmark and compare it with the previous one with DataSet.CompareBookmarks. If the result is 0 fine, if not, only then issue a 'GotoBookmark' for the previous bookmark. </p> <p>This way, as long as another user have not deleted/inserted records your grid will not seem to be jumpy, and if this is not the case at least you'd be on the same record.</p> <p><hr></p> <p><b>edit:</b> Here's some code sample that should reposition the selected record in the correct place even when there had been deletes/inserts in the dataset. Note that the code omits disabling/enabling controls, and the special case when there are less records to fill the grid for simplicity.</p> <pre><code>type TAccessDBGrid = class(TDBGrid); procedure TForm1.Button1Click(Sender: TObject); var BmSave, Bm: TBookmark; GridRow, TotalRow: Integer; begin GridRow := TAccessDBGrid(DBGrid1).Row; TotalRow := TAccessDBGrid(DBGrid1).RowCount; BmSave := DBGrid1.DataSource.DataSet.GetBookmark; try // close dataset, open dataset... if DBGrid1.DataSource.DataSet.BookmarkValid(BmSave) then DBGrid1.DataSource.DataSet.GotoBookmark(BmSave); Dec(TotalRow); if GridRow &lt; TotalRow div 2 then begin DBGrid1.DataSource.DataSet.MoveBy(TotalRow - GridRow); DBGrid1.DataSource.DataSet.MoveBy(GridRow - TotalRow); end else begin if dgTitles in DBGrid1.Options then Dec(GridRow); DBGrid1.DataSource.DataSet.MoveBy(-GridRow); DBGrid1.DataSource.DataSet.MoveBy(GridRow); end; Bm := DBGrid1.DataSource.DataSet.GetBookmark; try if (DBGrid1.DataSource.DataSet.BookmarkValid(Bm) and DBGrid1.DataSource.DataSet.BookmarkValid(BmSave)) and (DBGrid1.DataSource.DataSet.CompareBookmarks(Bm, BmSave) &lt;&gt; 0) then DBGrid1.DataSource.DataSet.GotoBookmark(BmSave); finally DBGrid1.DataSource.DataSet.FreeBookmark(Bm); end; finally DBGrid1.DataSource.DataSet.FreeBookmark(BmSave); end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload