By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,407 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,407 IT Pros & Developers. It's quick & easy.

Scrolling ListBox contents?

P: n/a

I have a simple application in which I am using a ListBox to display text
strings for logging purposes. When the text area becomes full the new lines
are added to the end and the vertical scroll bar becomes visible, however,
it does not automatically scroll up to show the most recent lines. What do
I need to do to get it to scroll all the way up each time a new line is
added, even though I might have previously manually pulled the scroll bar to
another position?

Ray Mitchell
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

I came accross this problem my self. I found that listBox.TopIndex sets
the top line in the listBox. I added a global:
int nbrListBoxItems;

and in the menu initilization added:
// TODO: Add any constructor code after InitializeComponent
nbrListBoxItems = testListBox.ClientSize.Height /
this determines the number of lines displayed.

Then when I added an entry I added the code:
if (testListBox.Items.Count > nbrListBoxItems)
testListBox.TopIndex = testListBox.Items.Count - nbrListBoxItems +1;

This works. I have been looking for a way to use a listBox event along
with this code so I don't have to added it after every add. I tried
using SizeChanged, but the code there never changes the listBox. I know
it must be a context thing, but I haven't figured it out yet. Anyone
have an answer?

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.