[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
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static i As Integer
i += 1
lstvListView.Items.Add(i.ToString, i)
'use the item Rectangle and the listviews' height property
'to determine how many on the list are visible
Dim r As Rectangle = lstvListView.GetItemRect(0)
Dim nVisibleItems As Integer = lstvListView.Height \ r.Height
'then use the topitem proerty with the number of visible items
'to know if the new item should be visible
If lstvListView.TopItem.Index + nVisibleItems >= lstvListView.Items.Count - 1 Then
lstvListView.EnsureVisible(lstvListView.Items.Count - 1)
End If
End Sub
GL
kevin
Re: Listview & Scrolling troubles
Thx Kebo, works fine!
Greetz,
djrud