Am I missing something or is there no webcontainer.scrollto anymore ?
Perhaps I should expand on this.
Pre Web 2.0, I could use scrollto to move to a particular position within a container which is useful when you have a list of containers within a container and you want to scroll to the bottom.
Frustrated !!
Thanks in advance for any help on this.
By the silence (and the LR https://documentation.xojo.com/api/user_interface/web/webcontainer.html) I assume you are correct that ‘there no webcontainer.scrollto’.
I’m in a meeting for another hour, then I’ll take a look if nobody else has. Should be some fairly simple JavaScript.
Cheers Anthony.
Much Appreciated
Here are a few methods you can use. Add to a module and call as outlined in comments:
Public Sub scrollTo(extends c as WebContainer, X as Integer, Y as Integer)
'// myContainer.scrollTo(10,100)
if Session <> Nil then
Session.ExecuteJavaScript( "var container = document.getElementById('" + c.ControlID + "');container.scrollTo(" + X.ToString + "," + Y.ToString + ");" )
end if
End Sub
Public Sub scrollToBottom(extends c as WebContainer)
'// myContainer.scrollToBottom
if Session <> Nil then
session.ExecuteJavaScript( "var container = document.getElementById('" + c.ControlID + "');container.scrollTop = container.scrollHeight - container.clientHeight;" )
end if
End Sub
Public Sub scrollToTop(extends c as WebContainer)
'// myContainer.scrollToTop
if Session <> Nil then
Session.ExecuteJavaScript( "var container = document.getElementById('" + c.ControlID + "');container.scrollTop = 0;" )
end if
End Sub
I think this is multi-session safe. Not operating at 100% today. @Greg_O_Lone can say for sure.
Thanks Anthony. Works a treat
Happy to help!
Hi,
I’m using 2021 r1 and have added the module and methods as in the solution, however my Webviewer Container only scrolls half way up the page and stops (Method I’m using is ScrollToTop I have tried putting in a value less than zero, but still no difference.
Any ideas would be appreciated.
Without knowing more about your setup, there’s not really much help I can provide. Could it be that you have overlapping containers? Maybe have containers within containers and need to scroll more than one or you’re scrolling the wrong one?
No, that wouldn’t work as 0 is the minimum value.
Hi Anthony,
Many thanks for your reply helped me tremendously and the problem is now solved - I was scrolling my PageViewer (Container) and not my page container array that was displayed within it.
Read your reply and the penny dropped for me, once again many thanks for your helpful nudge in the right direction to solve it.
All the best,
Colin
Happy to help!
Thanks Anthony. Very useful
Thanks for creating this. In my case I’m adding rows ■■■ webContainers to another webContainers (it looks like a proper listbox).
When I add a row and run the code, scrollToBottom scrolls to the bottom less one row.
Any ideas?
I just tested it and it seems to work for me. Try this project:
https://www.dropbox.com/s/uh41vzisabkv8nm/container-scrollto.xojo_binary_project?dl=1
That worked using the button to scroll. Look at this edit. The idea is to add the container and have it automatically scroll to the bottom so the bottom row always shows without the need to press a button. See button 4
https://www.dropbox.com/home?preview=container-scrollto+(scanlan).xojo_binary_project?dl=1
Couldn’t download your file (File Doesn’t Exist), but I added the following Shown event to ccVertical and it worked as expected:
Sub Shown() Handles Shown
me.scrollToBottom
End Sub
You could potentially use Timer.CallLater depending on what you need.
Could you upload that because there’s no ccVertical in the original?
How do you have do a download link to a dropbox file?
There is. I just redownloaded the example and modified it because I don’t normally keep stuff like this around.
The one I downloaded (thank you again) has ccParent rather than ccVertical and ccHorizontal.
Maybe the programming is not the same ?