Tuesday, April 1, 2008

Scroll Listbox Programmatically

String literals can be added to a ListBox control by using the Items.Add method. However, the ListBox control doesn't scroll automatically. One way to achieve this is to use the TopIndex property. This property determines the first entry to be visible in the ListBox.

Make the first entry visibile at the top of the ListBox:
this.listbox1.TopIndex = 0;

Show the last string of the control visible at the bottom of the ListBox (the last entry visible):
this.listbox1.TopIndex = this.listbox1.Items.Count - 1;


Anonymous said...

Just the quick answer I was looking for.

Thank you!

Filip said...

thank you, hate M$

serkan ince said...

Thanks , really worked for me