Scrolling your ListBox to the end of your last item

This is only simple tips :) Bagaimana caranya agar scrollbar listbox akan selalu menempati item terakhir yang ditambahkan? Secara default scrollbar tsb akan menempati posisi item yang paling awal. Untuk melakukan hal tsb kita hanya butuh set properti TopIndex dari ListBox tsb ke posisi item yang ditambahkan. Berikut code nya (atur properti ScrollAlwaysVisible dari ListBox tsb ke True) :

'//class level declaration
Private counter As Integer

1. Non-scrolling (default)

For i As Integer = 1 To 50
            Me.ListBox1.Items.Add("Items - " & counter.ToString)
            counter += 1
Next

2. Scrolling

For i As Integer = 1 To 50
            Me.ListBox1.Items.Add("Items - " & counter.ToString)
            counter += 1
Next
Me.ListBox1.TopIndex = Me.ListBox1.Items.Count - 1

Share this post: | | | |
Published Tuesday, July 25, 2006 1:12 AM by yulian
Filed under:

Comments

No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems