Results 1 to 4 of 4

Thread: Autoscrolling a listbox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210

    Autoscrolling a listbox?

    hi.
    i have a listbox in which a looped function continually adds items. the user can stop this and scroll down, but is there a way the listbox can be automatically scrolled down to the newest item?

    thanks.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Add timer , set its properties like this
    Enabled=True
    Interval=2000

    then add this code , it selects the last item was added .
    VB Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e
    2. As System.EventArgs) Handles Timer1.Tick
    3.         For i As Integer = 0 To 5
    4.             Me.ListBox1.Items.Add(i.ToString)
    5.         Next
    6.         Me.ListBox1.SelectedIndex = Me.ListBox1.Items.Count - 1
    7.     End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210
    heh
    VB Code:
    1. Me.lstEuler.SelectedIndex = Me.lstEuler.Items.Count - 1
    was exactly what i was looking for. i thought about selectedindex but didn't think it was going to scroll to select the item.

    thanks!

    p.s.: is there any reason for using Me.? it worked without is it necessary if there are multiple forms?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Not necessary but got used to OOP . Me refers to the instance you're currently working with . You can leave it out if you don't like but also it ease some part of typing the whole control name .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width