Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll to bottom of ListBox?

I am using a Winforms ListBox as a small list of events, and want to populate it so that the last event (bottom) is visible. The SelectionMode is set to none. The user can scroll the list but I would prefer it start out scrolled to the end.

Looking at the lack of support for things like ScrollIntoView, EnsureVisible, I am assuming I will need to create a custom control that inherits from ListBox; however I'm not sure what to do from there.

Some pointers?

like image 885
JYelton Avatar asked Jan 09 '12 23:01

JYelton


1 Answers

I believe you can do that easily by setting the TopIndex property appropriately.

For example:

int visibleItems = listBox.ClientSize.Height / listBox.ItemHeight; listBox.TopIndex = Math.Max(listBox.Items.Count - visibleItems + 1, 0); 
like image 165
Jon Avatar answered Oct 06 '22 01:10

Jon