excelformsvbalistboxlocked

Excel form listbox issue when using locked property


I'm having an issue with the way a listbox behaves on an Excel form. Steps to reproduce the issue:

When the form is first shown, I am able to navigate the list box normally, using arrow keys and page keys. However, after the double-click event is triggered, all keyboard navigation has no effect, including tabbing to other controls (if they're on the form). Clicking on the listbox does seem to work, and the focus outline is shown correctly, but there's something wrong with the way the focus is handled after the listbox is locked and then unlocked. What is going on?

Using Office 2013 32-bit edition.


Solution

  • I managed to replicate this issue, and setting the focus somewhere else before locking and unlocking the listbox worked for me:

    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
         Me.TextBox1.SetFocus 'or some other control.
         Me.ListBox1.Locked = True
         Me.ListBox1.Locked = False
         Me.ListBox1.SetFocus
    End Sub