[Lazarus] Control DBGrid row position

Luca Olivetti luca at wetron.es
Thu Nov 16 16:28:37 CET 2017


Is there a way to control the position of the selected row in a TDBGrid?

With a TStringGrid you can control it with TopRow, but TDBGrid has no 
such property and I couldn't find a way to do what I want.

I understand that TopRow wouldn't make sense in a DBGrid, but I need the 
same functionality: I have a huge amount of data (let's say 200000 
records), so, in the AfterScroll event of the query, when I'm 
approaching the end or the beginning of the dataset, I modify the query 
to show the previous or next page of data[*] and then reposition (with 
locate) to the same record where it was before changing the query.

It works well but the problem is that, when scrolling downward, the 
selected row jumps every time I do this, i.e., usually it's the bottom 
row, when I go down and reload the data this way, it jumps to the middle 
of the dbgrid[**]. I'd like a way to keep it in the bottom row, so the 
scrolling appears seamless.

It doesn't happen when scrolling upwards, probably because the dbgrid in 
this case always shows the data on the first row.

Then it would also be nice to control the size and relative position of 
the scrollbar, but that's another matter.

[*] actually I'm currently loading 200 records at a time and when 
scrolling I just shift the visible window 50 records up or down.

[**] more or less, it depends on the size of the window.

Bye
-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007


More information about the Lazarus mailing list