TextBox & ListBox Autoscrolling

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
ListBox Autoscrolling

Hi there,

I have code that adds list items to a list box.

How can i have it so that it automatically scrolls into view the last thing added as it is added?

Thanks.

EDIT:

Have figured it out for a text box:

VB.NET:
TextBox.SelectionStart = TextBox.Text.Length
TextBox.ScrollToCaret()
 
Last edited:
With a TextBox if you do this:
VB.NET:
myTextBox.Text &= newText
then it will not scroll to the end. If you do this:
VB.NET:
myTextBox.AppendText(newText)
it WILL automatically scroll to the end. If you want to scroll to the end any other time, when you're not adding text, then you would have to use the code you posted.

For the ListBox you can do this:
VB.NET:
myListBox.TopIndex = myListBox.Items.Count - 1
That attempts to make the last item in the ListBox the first displayed item by scrolling all the way down.
 
Back
Top