Board index » delphi » Place current record as first line in DBGrid?

Place current record as first line in DBGrid?

Hi,

I need to display the current record as the topmost line in my dbgrid after
I move the cursor of the dataset by program.

I tried a construction like:

type
  TCustomDBGridCracker = class(TCustomDBGrid);
...

  with TCustomDBGridCracker(dbgData) do
   ...

But I do not get further what to place after the "do" ;-(.

Thanks for your suggestions.
Heiko

 

Re:Place current record as first line in DBGrid?


On Sun, 4 Feb 2001 23:37:17 -0400, "Heiko Leicht"

Quote
<Heiko.Lei...@NOSPAM.conco.de> wrote:
>I need to display the current record as the topmost line in my dbgrid after
>I move the cursor of the dataset by program.

Here is a method that I use in a subclassed DBGrid.  You can move to
the top row with:
   MoveToRow(TopRow);

procedure TMyDBGrid.MoveToRow(NewRow: Integer);
// Scrolls the visible records so that the current record is shown
// on the NewRow position (if possible)
var
  Mark: TBookmarkStr;
begin
  Mark := DataLink.DataSet.Bookmark;
  // Set the current row to NewRow
  // (this also moves the record pointer)
  DataLink.ActiveRecord := NewRow;
  // Goto the original record
  DbiSetToBookmark(TDBDataSet(DataLink.DataSet).Handle,
    Pointer(Mark));
  // Force a reread of the record buffer with the current settings
  DataLink.DataSet.Resync([rmExact]);
end;

Row, TopRow and DataLink are protected properties of DBGrid, so they
should be used in a DBGrid subclass.

Jan

Other Threads