A ListView question: GetFirstVisible

A ListView question: GetFirstVisible

mdhutchinson
Advisor Advisor
417 Views
1 Reply
Message 1 of 2

A ListView question: GetFirstVisible

mdhutchinson
Advisor
Advisor
GetFirstVisalbe method of a ListView control obtains a ListItem. It is in-fact the first item that can be seen at the top of the list box.

The FindItem method along with EnsureVisible works to automatically scroll the control so the item is visible. This is working well... but
Question: Does anyone know how I might use this to return the scroll to the same location it was at prior to the procedure.
0 Likes
418 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Here is what i do. It also check to reselect a previously selected item after the rebuild of the list (Refresh type method)

[code]
'*****************************************
'Get the Key of the selectedItem
'*****************************************
Dim vSelIndex As Long, vTopIndex As Long
If MyListView.ListItems.Count <> 0 Then
If Not MyListView.SelectedItem Is Nothing Then
vSelIndex = MyListView.SelectedItem.Index
Else
vSelIndex = -1
End If
'*****************************************
'Get the index of the top visible
'*****************************************
vTopIndex = MyListView.GetFirstVisible.Index
'*****************************************
End If

'*****************************************
MyListView.ListItems.Clear
'*****************************************


'*****************************************
'Rebuild the List Content
'*****************************************
'*****************************************


'*****************************************
'Reselect
'*****************************************
Dim vLI As ListItem
If vSelIndex <> -1 Then
For Each vLI In MyListView.ListItems
If vLI.Index = vTopIndex Then
vLI.EnsureVisible
End If
Next vLI
For Each vLI In MyListView.ListItems
If vLI.Index = vSelIndex Then
vLI.Selected = True
vLI.EnsureVisible
End If
Next vLI
End If
Set vLI = Nothing
'*****************************************
[/code]

Try this out. I did not test it completly, but it should be pretty good. Note that I am using the index property to match, but you may use the KEY property......

Hope this helps.
0 Likes