Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Place current record as first line in DBGrid?

29 views
Skip to first unread message

Heiko Leicht

unread,
Feb 4, 2001, 10:37:17 PM2/4/01
to
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

Jan Sprengers

unread,
Feb 5, 2001, 7:45:35 AM2/5/01
to
On Sun, 4 Feb 2001 23:37:17 -0400, "Heiko Leicht"
<Heiko....@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

0 new messages