Jump to content


Photo

VisibleRow and ScrollToRow


  • Please log in to reply
8 replies to this topic

#1 bosjo

bosjo
  • Members
  • 75 posts
  • Gender:Male
  • Location:Märsta, Sweden

Posted 04 July 2018 - 02:27 PM

Hi Boki, long time no see...

 

I have not been particularly active the last couple of years, but might start doing some things again. But I am having problems with a fairly straight forward filtering operation, possibly combined with using ScrollToRow. I have made a simple testprogram and added that to this post (I am currently using XE2, and downloaded the latest version of v5.).

 

The program starts by adding 1000 rows to a Nextgrid, and for each click on the "Click me" button, the visibility of the first 500 rows are toggled and ScrollToRow(0) is called. I expected to see either the last 500 rows, starting from 501, or all of them, starting at row 1, but the results seem more or less random, probably depending on the position of the scrollbox when clicking on the button.

 

Is this a bug or am I doing something terribly wrong?

 

/bosjo

 

Attached File  Proj4boki.zip   81.41KB   3 downloads



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 06 July 2018 - 12:50 AM

Hi Bosjo,

I will test it. I need a little bit more time on v5, to do debugging. This is one of the reason why I started with v6.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 bosjo

bosjo
  • Members
  • 75 posts
  • Gender:Male
  • Location:Märsta, Sweden

Posted 19 July 2018 - 09:06 AM

Any news on this one?

 

A preliminary debug session points me to this line in the code (at the end of the ScrollToRow routine):

      VertScrollBar.Position := VertScrollBar.Position - Delta;

It seems VertScrollBar.Position has not been updated to reflect the position after the visibility of the first 500 lines have been toggled. For example:

1. Start program; line 1 is at the top of the grid.

2. Click "click me"; line 501 is now at the top.

3. Scroll down so that, say, line 782 is at the top of the grid

4. Put breakpoint at the indicated code

5. Click "click me"

After this, the program will stop at the line above -- VertScrollBar.Position is 281, Delta is 781, so the new VertScrollBar.Position will be -500, not 0.

 

This should be fairly simple to fix, I guess?



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 20 July 2018 - 08:29 PM

Hi Bosjo,

Sorry for delay again,

Probably is more to do than this fix, but maybe you can use it while I bring full solution. Version 5 is a little bit harder to debug and take more time.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 bosjo

bosjo
  • Members
  • 75 posts
  • Gender:Male
  • Location:Märsta, Sweden

Posted 21 July 2018 - 09:19 AM

Well, I don't really have a fix, just a clue to where the fix will be needed. But I might have been a bit too optimistic; I tried a "QnD" fix, but that didn't work:

      if Delta > VertScrollBar.Position then begin
        VertScrollBar.Position := 0; end
      else begin
        VertScrollBar.Position := VertScrollBar.Position - Delta;
      end;

It seems some other structure somewhere needs updating as well; the code above didn't change the behaviour of the grid at all.

 

Another clue to what might go wrong is how to fix the grid at runtime. To do that, proceed like this (after the 5 points above):

 

6. Click away the breakpoint and let the program run again; the grid should us now be positioned at "Line 501", and the first 500 rows are invisible.

7. Scroll down to the very bottom of grid; the bottom half of the grid is completely empty. After dropping the scrollbox, it jumps up a few pixels, and if you now scroll to the top, you will see that the topmost line has changed (it is "Line 16" here, but I suspect this is depending on the actual size of the grid).

8. Scrolling down to the bottom again until the scrollbox does not jump up, if necessary using the down arrow of the scrollbar a few times, will eventually restore the grid to its proper display, with "Line 1" being the topmost line.

 

So, the act of scrolling to the bottom will fix the display problem, and since I only use the program where this appears privately, I can live with it, but of course I would rather see it fixed.



#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 23 July 2018 - 06:27 PM

Hi Bosjo,

In you case, can not using Begin/EndUpdate help? It's a slightly slower (at least for bigger number of rows, but it work fine in your demo).
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 bosjo

bosjo
  • Members
  • 75 posts
  • Gender:Male
  • Location:Märsta, Sweden

Posted 23 July 2018 - 10:05 PM

Thanks for your input, stupid of me not to test that, but I somehow had got into my head that Begin/EndUpdate just delayed the repaint until after all changes where made.

 

However, this is just another workaround -- the grid in my "proper" program has something like 7000 rows (and about 10 columns), and an update without Begin/EndUpdate take up to about 5 seconds (it seems to depend on the number of rows being toggled). Since I do an incremental search, having to wait that long for to see whether the search string is precise enough to select the rows I want to select is not optimal; it might still be an improvement, but I need to test this. If I estimate an urgency value between 0 ("Everything is cool, man...!") and 10 ("FIRE! Run for your life!"), then I guess the current problem would be a 4 and this workaround a 3. But this is just because I am the only one ever to use this program; if this was an public program the urgency would be much higher; the workaround would maybe make it a non-showstopper, but only just.

 

So, I hope the clue that there is something (not) going on in the Begin/EndUpdate cycle makes it possible for you to find the bug.



#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 23 July 2018 - 11:30 PM

Hi Bosjo,

You can also try after EndUpdate to call:

  NextGrid1.VertScrollBar.Position := 0;
This will scroll to top, but also work fast.

If you have time, or maybe some smaller grid on your form - you can try to use v6 of grid. It's not that different, and one of the reason I write it is because maintenance is easier and quicker. Old v5 is very old (since early 2000's).
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 bosjo

bosjo
  • Members
  • 75 posts
  • Gender:Male
  • Location:Märsta, Sweden

Posted 24 July 2018 - 11:21 AM

But that does not cure the problem, it still scrolls to the wrong line because the grid has not yet realised that the lines above now are visible.

 

I will of course move to v6, but, I think, only for new projects. Maybe when I get the hang of how the new grid works I will convert some old projects, but I will not start that until I have got some understanding of benefits and possibly missing features of v6. Actually, when I think of it, this project is probably one of the simpler; currently, RowVisible is the only feature it is using (and the cells ObjectReference), so it might not be that hard to do the conversion. If you can confirm that v6 has some kind of RowVisible mechanism, I may give it a go...






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users