Yes the whole keyboard events in controls is a bit of a mess. I get that problem with a windows control too. I did something like this in the windows control. Basically create my own handlers. I don't have list boxes but I think that is just the up and down keys.
Public Sub Initialize()
WorkaroundTabIndexDefect()
End Sub
''' <summary>
''' Works around the tab index defect.
''' </summary>
Private Sub WorkaroundTabIndexDefect()
For Each ctr As Control In Me.Controls
SetKeyDownHandlers(ctr)
Next
End Sub
''' <summary>
''' Sets the key down handlers.
''' </summary>
''' <param name="ctr">The CTR.</param>
Private Sub SetKeyDownHandlers(ByVal ctr As Control)
Dim txtCtr As TextBox = TryCast(ctr, TextBox)
If txtCtr IsNot Nothing Then
txtCtr.AcceptsTab = True
txtCtr.AcceptsReturn = True
Dim evh As KeyEventHandler = New KeyEventHandler(AddressOf WorkaroundKeyDown)
AddHandler txtCtr.KeyDown, evh
Else
ctr.TabStop = False
End If
If ctr.Controls.Count > 0 Then
For Each subCtr As Control In ctr.Controls
SetKeyDownHandlers(subCtr)
Next
End If
End Sub
''' <summary>
''' Workarounds the key down.
''' </summary>
''' <param name="sender">The sender.</param>
''' <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs" /> instance containing the event data.</param>
Private Sub WorkaroundKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
Try
If Me.ActiveControl IsNot Nothing Then
Select Case e.KeyCode
Case Keys.Return
Dim btnCtr As Windows.Forms.Button = TryCast(Me.ActiveControl, Windows.Forms.Button)
If btnCtr IsNot Nothing Then
btnCtr.PerformClick()
End If
Case Keys.Tab
If e.Shift Then
Me.SelectNextControl(CType(sender, Control), False, True, True, True)
Else
Me.SelectNextControl(CType(sender, Control), True, True, True, True)
End If
End Select
End If
Catch ex As Exception
Trace.WriteLine(ex)
End Try
End Sub