Selected item in listbox not highlighting

  • Hi,


    I have a userfrom (Word 2010) with a listbox (lbPrinterList) and a command button (cmdClose).
    In the Initialize event, i read the previous selectted listindex from the local registry.
    I create a list of the the installed printers and
    When running it the first time, I'll set the default listindex to -1 (nothing selected).
    Then I create a list of installed printers and populate the listbox with it.


    When I click then on a listitem (listbox click event ) I save the listbox listindex to the local registry.


    Once i run the initialize event again i'll read the previous listindex back from the registry, but the listitem will not highlight, no matther what I try.


    What am I doing wrong ?
    Hope someone will bring up a solution.


    Here's the full userform code + the printerlist code (source: Chip Pearson)


    Best regards,
    Ludo

  • Re: Selected item in listbox not highlighting


    One way is to do the following:


    1. Use an unused cell on any sheet, make it a Named Range with the name "ListIndex", enter -1 in that cell ( you can set the font colour to the same as fill colour so that the value will not show).
    2. Use this as the code that launches the user form

    Code
    Sub LoadForm()
        With UserForm1  '// Change name of user form to suit
            .lbPrinterList.ListIndex = Range("ListIndex")
            .Show
        End With
    End Sub


    3. Use this as the lbPrinterList Click event code

    Code
    Private Sub lbPrinterList_Click()
        
    [ListIndex] = ListBox1.ListIndex
    End Sub

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: Selected item in listbox not highlighting


    Quote from KjBox;795758

    One way is to do the following:


    1. Use an unused cell on any sheet, make it a Named Range with the name "ListIndex", enter -1 in that cell ( you can set the font colour to the same as fill colour so that the value will not show).
    2. Use this as the code that launches the user form

    Code
    Sub LoadForm()
        With UserForm1  '// Change name of user form to suit
            .lbPrinterList.ListIndex = Range("ListIndex")
            .Show
        End With
    End Sub


    3. Use this as the lbPrinterList Click event code

    Code
    Private Sub lbPrinterList_Click()
        
    [ListIndex] = ListBox1.ListIndex
    End Sub


    Hi
    Thanks for the answer.
    Sorry for the late reply, I'm on holiday for the moment.
    Will give it a try when back at work.


    best regards,
    Ludo


    still searching for the Star ....

  • Re: Selected item in listbox not highlighting


    You're welcome.


    Quote

    still searching for the Star ....


    Go to any of my replies to this thread, look at the menu bar at the bottom of the Post, there should be an "IP" icon on the extreme right of that menu bar then a star and "GIVE REPUTATION", click either the star or "GIVE REPUTATION".

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!