WebListBox.ScrollTo

Occasionally I find a WebListBox’s scrolling is out of sync with its current ListIndex. That is, its selected row is not visible on the screen, so I have to manually scroll up or down to expose that selected row. E.g., the WebListBox has 10 rows, and the current bottom row is the record 10, but the selected record is record 15. I can’t find a way to accomplish this with WebListBox.ScrollTo. It seems that if the selected row is not visible (as in the above example), that method is useless, as it turns on the RowIndex, not the ListIndex. Am I missing something here?

ScrollTo scrolls to a particular row. I’m curious though, ListIndex is a row index so I’m not sure what you are asking.

Thanks, Greg. I had thought that if the selected record is not visible (below the bottom row, for instance), ScrollTo couldn’t do anything because it scrolls to the visible row passed as a parameter. At least that’s what I thought explained why my Shown code failed to scroll to the selected record in the above example. But now that I place that ScrollTo code in a button to test it, I see it indeed scrolls to the selected record even when not initially visible in the WebListBox. So I need to do more exploring to see why I can’t get it to work at the end of the Shown event.

Probably because the list hasn’t been populated on the browser at that point. The drawing actually happens in the next event loop.

I suspected the WebListBox filling wasn’t complete. Not sure what is meant by “next event loop.” Is there a place where I can read up on that and figure out how to deal with this? I guess it involves some way of determining how to wait for a WebListBox to completely fill on the browser before a different piece of code is run.

In this case, it’s really not a Shown event. It’s a method that acts like a Shown event for a WebContainer that has a WebListBox. It fills the WebListBox, among other things, when its embedded WebContainer is made Visible again. It’s a way of making the invisible embedded WebContainer essentially run a Shown event each time it’s made Visible again.

There’s not much to “read up” on. When rows are sent to the listbox on the browser, the refresh is deferred so that it doesn’t get refreshed over and over because it would be exponentially slow. Unfortunately the ScrollTo is getting called before the deferred code executes.

What you could do is set a timer with a mode of “single” and in the action event make the ScrollTo call.

Thanks for your patience on this, Greg. I assume such a WebTimer need to “see” that the WebListBox is filled in the browser before executing its Action code? What sort of property would I use for this?

Oh. Wait. You suggest a mode of Single. So it doesn’t have to continously run and look for the listbox to fill. I’ll try that.

Works perfectly. Thanks, Greg.

I was just looking for known weblist scroll issues. – I’ve noticed that when I use multiple WebPages in a WebApp and switch between them, a WebTextArea remembers exactly where I have scrolled to, whereas a WeblistBox always places the scroll bar at the top whenever I switch to the page. It does remember selected rows…but the scroll position seems to be lost whenever I swap between pages. Thinking maybe I can save off the scroll position on WebPage Exit and use the ScrollTo operation described above.

To have your WebListBox ScrollTo the selected row, you can place a Timer called Timer1 in each such WebPage and set its Mode to Off and Period to 500, with an Action something like this:

If MyListBox.RowCount > 0 And MyListBox.ListIndex > -1 Then MyListBox.ScrollTo(MyListBox.ListIndex) End If Me.Mode = Timer.ModeOff

Then at the end of each WebPage.Shown event, you set Self.Timer1.Mode = Timer.ModeSingle.