[RESOLVED] refresh/populate listvew without losing selected VB6
I am trying to repopulate or refresh a listview but the problem is the selected item loses, how can I make the selected item(index), selected again when the listview refreshes???? I cannot find any answer to this question in VB6 :(
Re: refresh/populate listvew without losing selected VB6
Have you tried storing the selected item in a var then setting the selecteditem = the var you used to hold it?
Re: refresh/populate listvew without losing selected VB6
before you refresh the listview, save the index in another variable (iSavedIndex), refresh, then:
Code:
Set ListView1.SelectedItem = iSavedIndex
Re: refresh/populate listvew without losing selected VB6
i know how to do it in listbox but in listview i dont know...
Re: refresh/populate listvew without losing selected VB6
how to get the selected item by index
Re: refresh/populate listvew without losing selected VB6
I think you would need to use a var that is defined as a listitem and assign it to the selecteditem from the list view then back again.
Re: refresh/populate listvew without losing selected VB6
from the above code
vb Code:
dim isaveindex as integer
Private Sub lvP_ItemClick(ByVal Item As MSComctlLib.ListItem)
isaveindex = Item.Index
End Sub
private sub cmdrefresh()
Set lvProcess.SelectedItem = isaveindex '>> object required error
end sub
its not working
Re: refresh/populate listvew without losing selected VB6
isn't the Index simply an Integer?
I don't know much about ListView but I would have thought
Code:
iSavedIndex = Listview1.SelectedItem.Index
Do your stuff
then
Code:
ListView1.SelectedItem.Index = iSavedIndex
Doesn't it work?
Re: refresh/populate listvew without losing selected VB6
It may work, I have not actually tested it, not sure if the other method I gave would work either. The poster should try your method above and if that doesn't work try it with a listitem and report back the results.
Re: refresh/populate listvew without losing selected VB6
I notice the OP used .ListItem instead of .SelectedItem. That may be the problem?
Re: refresh/populate listvew without losing selected VB6
property is read-only (Error 383)
Re: refresh/populate listvew without losing selected VB6
i have tried:
vb Code:
lvP.SelectedItem.Index = lvP.ListItems(iSavedIndex)
but it gives an error type mismatch
Re: refresh/populate listvew without losing selected VB6
ok fixed the code added thank you! good night :)
Re: refresh/populate listvew without losing selected VB6
w8, how can I scroll to the selected index
Re: refresh/populate listvew without losing selected VB6
got it used:
vb Code:
lvP.SelectedItem.EnsureVisible
for those who needs the code im sharing it