How to move the active record in a table to a certain position on a TDBGrid (Views: 29)
Problem/Question/Abstract: Does anyone know of a way to move the active record in a table to a certain position on a TDBGrid (i.e. the centre of a grid, top or bottom, or row number) Answer: This is a method that I use in a subclassed DBGrid. You can save the original row with: OldRow := Row - TopRow; and move with: MoveToRow(OldRow); 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 can only be used in (or through) a subclass. |