Recent

Author Topic: [Solved] DBGrid Mouse Wheel "hesitation"  (Read 2464 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
[Solved] DBGrid Mouse Wheel "hesitation"
« on: July 16, 2018, 11:47:27 pm »
Using the Mouse Wheel, my DBGrid does not scroll immediately; i.e. after the initial few rolls my grid hassn't scrolled at all. For example, if there are 20 rows visible in my grid I need to roll the mouse wheel 20 DOWN times before the top line moves up one line. Once I get the first movement in the desired direction (which is always based upon the number of visible lines) the grid does move one line with each roll-click of the mouse wheel.

If I then change direction and start rolling UP, once again I need to roll-click 20 times to get the grid moving. Is there a way to make the grid responsive to the initial roll-click of the mouse wheel?
« Last Edit: July 22, 2018, 07:47:34 pm by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: DBGrid Mouse Wheel "hesitation"
« Reply #1 on: July 21, 2018, 07:12:28 am »
hi, try enabling
Optionss > dgThumbTracking

regards  :)

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: DBGrid Mouse Wheel "hesitation"
« Reply #2 on: July 21, 2018, 11:11:29 am »
This will not work. The DBGrid is constructed such that it loads only the visible rows around the active dataset (maybe a few more). If you want to scroll the grid but keep the cursor the grid would have to reload records which normally would not be available. This certainly is doable, but requires massive rework of the inner structure of the grid.

If you don't have too many records why don't you load all records into a StringGrid which has a property MouseWheelOption: if you set this to mwGrid the active cell will remain in its current row and move out of view while you scroll with the mousewheel.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: DBGrid Mouse Wheel "hesitation"
« Reply #3 on: July 22, 2018, 07:47:17 pm »
I discovered an approach which works well for me, although it seems a bit 'kludgy'.
I've added a tDBNavigator [NavBar] to the form with the DBGrid, and wired it up appropriately. I set visible to false because I don't really want to see it.

On FormShow I execute

  NavBar.DataSource.DataSet.First;
  NavBar.DataSource.DataSet.Last;

which establishes the range of the DB and sizes the scroll button correctly.

Then I use a Query.Locate to position the scroll bar in the correct place and make the desired record visible.

YMMV
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018