|
-
Jun 9th, 2012, 09:33 AM
#1
Thread Starter
Junior Member
[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
-
Jun 9th, 2012, 09:39 AM
#2
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?
-
Jun 9th, 2012, 09:46 AM
#3
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
-
Jun 9th, 2012, 09:48 AM
#4
Thread Starter
Junior Member
Re: refresh/populate listvew without losing selected VB6
i know how to do it in listbox but in listview i dont know...
-
Jun 9th, 2012, 09:50 AM
#5
Thread Starter
Junior Member
Re: refresh/populate listvew without losing selected VB6
how to get the selected item by index
-
Jun 9th, 2012, 09:53 AM
#6
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.
-
Jun 9th, 2012, 10:00 AM
#7
Thread Starter
Junior Member
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
-
Jun 9th, 2012, 10:08 AM
#8
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?
-
Jun 9th, 2012, 10:10 AM
#9
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.
-
Jun 9th, 2012, 10:12 AM
#10
Re: refresh/populate listvew without losing selected VB6
I notice the OP used .ListItem instead of .SelectedItem. That may be the problem?
-
Jun 9th, 2012, 10:17 AM
#11
Thread Starter
Junior Member
Re: refresh/populate listvew without losing selected VB6
property is read-only (Error 383)
-
Jun 9th, 2012, 10:24 AM
#12
Thread Starter
Junior Member
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
-
Jun 9th, 2012, 10:27 AM
#13
Thread Starter
Junior Member
Re: refresh/populate listvew without losing selected VB6
ok fixed the code added thank you! good night
-
Jun 9th, 2012, 10:36 AM
#14
Thread Starter
Junior Member
Re: refresh/populate listvew without losing selected VB6
w8, how can I scroll to the selected index
-
Jun 9th, 2012, 10:41 AM
#15
Thread Starter
Junior Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|