Results 1 to 15 of 15

Thread: [RESOLVED] refresh/populate listvew without losing selected VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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?

  3. #3
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    i know how to do it in listbox but in listview i dont know...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    how to get the selected item by index

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    from the above code

    vb Code:
    1. dim isaveindex as integer
    2.  
    3. Private Sub lvP_ItemClick(ByVal Item As MSComctlLib.ListItem)
    4.  isaveindex = Item.Index
    5.  
    6. End Sub
    7.  
    8. private sub cmdrefresh()
    9.  Set lvProcess.SelectedItem = isaveindex '>> object required error
    10. end sub
    its not working

  8. #8
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    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?

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  10. #10
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: refresh/populate listvew without losing selected VB6

    I notice the OP used .ListItem instead of .SelectedItem. That may be the problem?

  11. #11

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    property is read-only (Error 383)

  12. #12

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    i have tried:
    vb Code:
    1. lvP.SelectedItem.Index = lvP.ListItems(iSavedIndex)
    but it gives an error type mismatch

  13. #13

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    ok fixed the code added
    vb Code:
    1. Set
    thank you! good night

  14. #14

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    w8, how can I scroll to the selected index

  15. #15

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    30

    Re: refresh/populate listvew without losing selected VB6

    got it used:
    vb Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width