Always show last line TextArea

I want to always show the last line of text when I append to a TextArea. The XOJO Documentation for TextArea.VerticalScrollPosition has no example for me to refer to. (At least I can not see one). Currently I have to manually scroll the vertical scroll in order to see what has been added. Does anyone know where to find an example?

If you set the selection to the last position of the textarea after you add your text it will move the view to that location. So if you are using 2019r2 try:

Me.SelectionStart = Me.Value.Length

1 Like

That did not work for me. I get an error telling me textarea has no member named “Value”. So I tried the following
TextAreaResults.SelStart = TextAreaResults.SelLength

I don’t get an error but it doesn’t display the last line, I still have to manually scroll.
At least you have given me some idea as to the area to look into.

The name of my TextArea control is TextAreaResults
So, I tried this as well and this did not work either.
TextAreaResults.SelStart = Len(TextAreaResults.text)
I still have to manually scroll to see what was added to the TextArea
I will keep tinkering

What version of xojo are you using and on what operating system?

this is what I do in 16r3 to 19r1.1:-


this has worked to do exactly what you are asking for me for years.

for 19r2 I have no idea, but I expect it will work fine but you will get depreciation warnings, which you can ignore.

I am using 2019 Ver 1.1 on a Macbook Pro 2012 running Mojave latest version, 16 gig ram, 1T SSD, 2.3 gig Intel i7
I tried Mark’s suggestion and it worked like a charm.
Thank you for the help. The complier did not complain.

great! I think that is my first green tick!, even if its not actually on my post…

Glad you got it sorted. If you are making your app cross platform, you might not know that Marks code will behave differently under windows and they’ll have to the use the SelStart code. Just pop it in some #ifs so it uses one method on the mac and another in windows.

after Julian had said that this would behave differently on windows I thought I had better look at it as my app is running on windows as well as Mac computers without any problems.

so it turns out that the code above is required on Mac to make it scroll to the bottom, but on windows it is completely unnecessary.
in fact removing that code completely on windows does not stop the window scrolling exactly as expected without any other code making the textarea perform that function.

after looking more closely, but not actually doing any testing, I populate the textarea by this code:-


I can only think that on windows this automatically does the scroll to the bottom?

AppendText does move to the bottom, but as soon as you tab through the control or use the scrollbar the “to bottom” feature of AppendText stops working and you either end up with a flickering scrollbar where it jumps to the end and back again or it just stalls the view where you left it for it to never autoscroll again.

hi Julian,

I am sure this is a little off topic, but for completeness I tried your explanation of the AppendText.
having never had a reported problem from a user and myself not having a windows machine in use, it was news to me, but after testing it I realize why it has never come up.

what you describe does indeed happen to a large extent, but if you move the scroll bar to the bottom of the text it does indeed work as expected again without any flickering and the AppendText just keeps it scrolling away.

this is actually why I never had any one report it, the textarea in my app is actually a passive view of incoming raw data that is used simply as an indication of activity with the raw data being decoded for display in specific data fields, I suspect no one has ever needed to manually alter the data in there and it has never shown the issue.

I can only report what I see in my MacMini running BootCamp with up to date win7 on it, I presume any windows version will be the same as the control is the same.


If it works for you then its all good. I’m just letting people know the flaws, take them or leave them its up to the reader :slight_smile:

yes I agree with letting people know of the flaws, and I was offering a more in depth explanation of the flaw you highlighted, which was not complete.
I will be doing more test to add the more expected way of having auto scroll for sure in windows and a silent app upgrade can follow to fix it.
I have no doubt that someone right now will be using my app this weekend and see this problem after 3 years of it never being seen just because we talked about! at least I will be able to say, yes don’t worry, its fixed in this new update I have right here!

Cool, let us know how you get on?

so I posted an update to my users (all in one place and only 50 or so machines) the IT guy said, 'oh yeah I saw that jumping so I just told them to scroll down to the bottom and it goes away"

glad they are all windows users or it would have been mayhem.

so for the first time in my life I have to take my hat off to the IT guy and buy him a sangria.