Results 1 to 3 of 3

Thread: [RESOLEVD] Listview & Scrolling troubles

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    15

    Resolved [RESOLEVD] Listview & Scrolling troubles

    Hi,

    I'm using a listview control to have a log screen. So every 10 seconds a new line is added, at the bottom.

    Now, I know how to code that the last line added to the listview is always visible by using the ensurevisible property.

    -----------------------------------------------------------------------------
    Public Sub AddToLstv(ByVal lstvListView As ListView, ByVal AddItem As String, ByVal ImageNumber As Integer)

    lstvListView.Items.Add(AddItem, ImageNumber)
    lstvListView.EnsureVisible(lstvListView.Count - 1)

    End Sub
    -----------------------------------------------------------------------------

    But when I try to read my log window, it is ennoying that the listview jumps down everytime a new line is added. So I always have to search again where I was reading.

    So, I would like my listview having another behaviour:
    - When the scrollbar is in the down position, I see every new line added & the listview scrolls automatically up.
    - But when I put the scrollbar up, the listview keeps adding new lines, but doesn't jump everytime to that new line, and stays simple on the place I'm reading.

    The same kind behaviour like in a chat-channel on irc, or when using a ftp-client, etc...

    Anybody can help, or suggest a solution?

    Thx,
    djrud
    Last edited by djrud; Jun 15th, 2005 at 07:15 AM. Reason: Resolved

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Listview & Scrolling troubles

    Hi djrud,
    I did a little mock up using a listview and a button. It seemed to do what you are looking for
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Static i As Integer
    4.         i += 1
    5.         lstvListView.Items.Add(i.ToString, i)
    6.  
    7.         'use the item Rectangle and the listviews' height property
    8.         'to determine how many on the list are visible
    9.         Dim r As Rectangle = lstvListView.GetItemRect(0)
    10.         Dim nVisibleItems As Integer = lstvListView.Height \ r.Height
    11.  
    12.         'then use the topitem proerty with the number of visible items
    13.         'to know if the new item should be visible
    14.         If lstvListView.TopItem.Index + nVisibleItems >= lstvListView.Items.Count - 1 Then
    15.             lstvListView.EnsureVisible(lstvListView.Items.Count - 1)
    16.         End If
    17.     End Sub
    GL
    kevin
    Last edited by kebo; May 11th, 2005 at 11:11 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    15

    Re: Listview & Scrolling troubles

    Thx Kebo, works fine!

    Greetz,
    djrud

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