views:

128

answers:

1

winforms .net 3.5 Ultrawingrid 9.2

In my subclass of Ultrawingrid.Ultragrid :

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)

    If e.KeyCode = Windows.Forms.Keys.Tab andalso e.control = True then 
        SetFocusToNextControl(True)
    End if

   Mybase.OnKeyDown(e)

End Sub

This works fine. But when the grid is dropped on a TabControl tabpage, the ctrl-tab looks very different to the sub above. e.keycode is seen as controlkey {17}

I realize that by default cntrl-Tab moves between tabpages. I need to override this behavior. My thought is I probably need a subclass of the tabControl which will pass the keycombo through just as the form does but I confess to being clueless as to how to accomplish that. I tried to override the onkeydown of a tabcontrol subclass and just issuing a return and not and base call to onkeydown if the ctrl-tab combo was pressed but it seemed to see the e.keycode as controlkey as well.

FWIW I tried a different combination like ctrl-E and got pretty much the same result with focus disappearing from the grid but not going anywhere I could detect. The sub still saw the e.control as controlkey.

Oddly, ctrl-X, ctrl-A etc all work in the grid and a ctrl-Delete combo I put in the subclass for deleting a row works fine.

Once again - grid directly on form and it all works.

I'm definitely over my head on this one. Guidance much appreciated. vb or c# fine.

TIA

A: 

I'm glad you asked that question ;-)

To pass the ctrl-tab through the TabControl :

Public Class MyTabControl
Inherits MicroFour.StrataFrame.UI.Windows.Forms.TabControl

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Tab AndAlso e.Control Then
    e.Handled = False
    e.SuppressKeyPress = False
Else
    MyBase.OnKeyDown(e)
End If

End Sub
End Class

On the advice of someone wiser I have moved the navigation code to my baseform class (code to delete single row with ctrl-Delete in Ultragrid remains in onkeydown of grid subclass)

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
                                       ByVal keyData As System.Windows.Forms.Keys) _
                                       As Boolean
    '-- check for unique keystrokes
    Select Case keyData
        Case Keys.Control Or Keys.Tab

            '-- created to be able to tab out of a Grid control 
            '-- Unfortunately direct at this point still moot for grids on 
            '-- tabcontrols as I have to set focus() to next control 
            '-- explicitly on leaving groupbox containing grid on tabpage

            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)
        Case Keys.Control Or Keys.E

    End Select

    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

I need to explicitly set the focus() to the next control on the Leave of the groupbox containing the Ultragrid as it seems to forget where it is supposed to go based on the form's TabOrderController, but this is a small price to pay. I hope to have that part genericised shortly.

Will post further refinements for anyone interested.

Charles Hankey