magicmandan
Programmer
- Mar 9, 2010
- 13
Hi all,
I have an unbound single select listbox on an unbound form.
I have the following code on the On Key Down event of the list box so that users can remove an item from the listbox using the left arrow key on the keyboard.
After removing the selected item I want the user to have the ability to scroll through any other items in the list using the up and down keyboard keys and if desired remove another selected item.
The problem is that after an item is removed the up and down arrows on the keyboard will no longer scroll through the remaining items in the listbox unless i click on another control on the form and then click back on item in the listbox.
---KEYDOWN CODE----
Private Sub lbLM_KeyDown(KeyCode As Integer, Shift As Integer)
Dim strItemR As String
Dim strTXT As String
Dim I As Integer
If KeyCode = vbKeyLeft Then
If Me.lbLM.ListCount = 0 Then
Exit Sub
End If
strItemR = Me.lbLM.Column(0)
Me.lbLM.RemoveItem (strItemR)
If Me.frLM = 1 Then
strTXT = ""
For I = 0 To Me.lbLM.ListCount - 1
strTXT = strTXT & lbLM.Column(3, I) & ". "
Next I
Me.txtLM.value = strTXT
End If
Me.txtAllDL = allDislikes()
If Me.lbLM.ListCount = 0 Then
Else
Me.lbLM.Selected(0) = True
End If
End If
'MsgBox Screen.ActiveControl.Name
End Sub
---CODE END-----
I have found that if i uncomment the line: MsgBox Screen.ActiveControl.Name
then after a the msgbox is shown the up and down arrow keys work as they should.
Could anyone shed any light as to why the up down arrow keys do not work after remove item.
(I have a similar set up for populating the listbox above from another listbox (lbIngList) using the right arrow key and 'Me.lbLM.AddItem Item:=strItem' which works perfectly', i.e. the item is added and i can still scroll up and down lbIngList)
I have an unbound single select listbox on an unbound form.
I have the following code on the On Key Down event of the list box so that users can remove an item from the listbox using the left arrow key on the keyboard.
After removing the selected item I want the user to have the ability to scroll through any other items in the list using the up and down keyboard keys and if desired remove another selected item.
The problem is that after an item is removed the up and down arrows on the keyboard will no longer scroll through the remaining items in the listbox unless i click on another control on the form and then click back on item in the listbox.
---KEYDOWN CODE----
Private Sub lbLM_KeyDown(KeyCode As Integer, Shift As Integer)
Dim strItemR As String
Dim strTXT As String
Dim I As Integer
If KeyCode = vbKeyLeft Then
If Me.lbLM.ListCount = 0 Then
Exit Sub
End If
strItemR = Me.lbLM.Column(0)
Me.lbLM.RemoveItem (strItemR)
If Me.frLM = 1 Then
strTXT = ""
For I = 0 To Me.lbLM.ListCount - 1
strTXT = strTXT & lbLM.Column(3, I) & ". "
Next I
Me.txtLM.value = strTXT
End If
Me.txtAllDL = allDislikes()
If Me.lbLM.ListCount = 0 Then
Else
Me.lbLM.Selected(0) = True
End If
End If
'MsgBox Screen.ActiveControl.Name
End Sub
---CODE END-----
I have found that if i uncomment the line: MsgBox Screen.ActiveControl.Name
then after a the msgbox is shown the up and down arrow keys work as they should.
Could anyone shed any light as to why the up down arrow keys do not work after remove item.
(I have a similar set up for populating the listbox above from another listbox (lbIngList) using the right arrow key and 'Me.lbLM.AddItem Item:=strItem' which works perfectly', i.e. the item is added and i can still scroll up and down lbIngList)