Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-11

Control DBGrid row position

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

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

Reply by email

Luca Olivetti
to Luca Olivetti

El 16/11/17 a les 16:28, Luca Olivetti via Lazarus ha escrit:

Show quoted text 17 lines
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.

An ugly workaround:

         moved:=Query.MoveBy(-50);
         Query.MoveBy(-moved);
Show quoted text 6 lines
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.

For the time being I just don't show the scrollbar.

Bye

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

Reply by email