I have a textfield:


I’d like to programatically scroll it to the end of the field so the user can see XYZ at the end of the text and continue typing. This seems like such a basic thing, but I’m stumped. Seems like .HorizontalScrollPosition is made for this but I can’t seem to get it to work.

Any hints would be appreciated. Thanks in advance.

Maybe you need to (also) set the SelectionStart?

Thanks for the reply. I’ve tried that too. It puts the selection at the end but it doesn’t scroll there.

Strange. I’ve tested it using Xojo 2024r1 on Windows 10.
Below the TextField i’ve placed a Slider and in it’s ValueChanged Event i use:

Var seletedLength As Integer = TextField1.SelectionLength
TextField1.SelectionStart = Me.Value
TextField1.SelectionLength = seletedLength

I think it works as you’d expect it.
As you can see, i did not even use the HorizontalScroll Position. But i set the Focus to the TextField, so that the user can see the Cursor. :wink:

However, I have a similar problem myself. Only with the DesktopSearchField… (see:

1 Like

I can confirm this works on Windows. It does not on MacOS.



In regards to the SearchField, there are some great alternatives by both Einhugur and GraffitiSuite, but both require payment.

Thank you. I have a valid License for Einhugur, but i try to avoid Plugins wherever possible. And the Einhugur SearchControl has it’s own flaws (regarding Focus f.e.). But in general it’s a really nice Control. :+1:

1 Like

New issue created:

One quick note, removing .SetFocus fixes the cursor position issue on MacOS because .SetFocus automatically selects all on the textfield. But it still does not scroll the horizontal position of the textfield the way it does on Windows.

If anyone can think of a workaround to horizontally scroll in the textfield for MacOS, I’m all ears.

1 Like

Hi @Christian_Wheel ,

I think you might need is this:

from the MacOSLib project

And the “NsText.ScrollRangeToVisible” method in particular feels like the required item?

Apple’s docs on the same item:

which say:

“Scrolls the receiver in its enclosing scroll view so the first characters of aRange are visible.”



Thanks Anthony,

Appreciate the link. This is my first go at MacOSLib and I’ve spent the last hour trying to do the most basic of things and I can’t even get the example project to run without a hard crash on startup. Will keep at it but I fear there’s more to learn here than I have time for. Even so, I appreciate you giving me a direction to head towards. Cheers!

Seems as if this will be fixed in 2024R2. Thanks everyone!