Ivan suggested code for the form.processcmdkey() which worked as far as getting out of a grid with Ctrl TAB but it was a mystery as to just where focus went after that. It left the groupbox holding the grid but then ...?
The problem became apparent when i realized he was calling the form's selectNextControl which uses the form TabOrder not the TabOrderController tab order. So I made a modification, adding a property my form baseclass which held a reference to the TabOrderController.
That's when I found out me.ActiveControl in a SF Maintenance form always returns ToolstripContainer1
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean
' Just break here and you'll see me.Activecontrol isn't the grid or groupbox or whatever you think it is
' so this code just sends the focus to whatever is next in the tab order after ToolstripContainer1
Select Case keyData
Case Keys.Control Or Keys.Tab
'-- created to be able to tab out of a Grid control
Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
Case Keys.Control Or Keys.Shift Or Keys.Tab
Me.SelectNextControl(Me.ActiveControl, False, True, True, True)
End Select
'This code - orginally before the block above, blows up since GetNextFocusableControl
'does not see ToolstripContainer in its dictionary
'' If Not Me.TOC() Is Nothing Then
'Select Case keyData
' Case Keys.Control Or Keys.Tab
' '-- created to be able to tab out of a Grid control
' Me.TOC.GetNextFocusableControl(Me.ActiveControl).Focus()
' Case Keys.Control Or Keys.Shift Or Keys.Tab
' Me.TOC.GetPreviousFocusableControl(Me.ActiveControl).Focus()
' Return True
' End Select
'end if
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
So far I cannot find a way to determine - at the form level - what control really has focus.
Suggestions welcome.
This does explain why I needed to tell the groupbox in leave where to set the focus. Seems if I"m going to do that I might want to just raise the Leave event of the containng goupbox in response to the Ctrl-Tab ( then we also get into the question of how the leave of the groupbox knows what the last keypress was - i.e. ctrl-Tab or ctrl-Shift-Tab)
Have learned a lot along the way. Very surprised to find there is no generic way to find a TabOrderController on a form, though I settled on creating a property of that type in the baseform as was pleased to see the property become a cbo picker, just as Greg suggested on picking a control for the groupbox exit.
So, does anyone know :
- How to find the
real activecontrol (from the form level)
- How to find a tabcontroller in a form baseclass
- How to determine the last key pressed in the Leave of a Groupbox
TIA