Ultrawingrid - handling keypress and setting focus to row on enter


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K


Two Ultrawingrid issues :



What is the best way to cause the focus to go to the first column of the first row when the grid is entered via tabbing from the previous control. i.e. so you can immediately start typing or tabbing through the gird.



How does one handle the keypress so that a ctrl-Tab will exit the grid and move to the next control in the TOController tab order.?



Thanks



( if you know the answer and could email it to me I'd appreciate it as i may need it before the forum goes down for maintenance)



Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hiya.

This is to Exit and Set Focus to next control. I haven't been able to catch Ctrl+Tab. If you manage it, please let me know:

    Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.E AndAlso e.Control Then
            SetFocusToNextControl(True)
        End If

        MyBase.OnKeyDown(e)
    End Sub

And this is to enter in Edit mode:

    Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
        Me.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ActivateCell)
        Me.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)

        MyBase.OnEnter(e)
    End Sub

Hope it helps. Wink

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Super ! Thanks Ivan. I'll try these tonight.



SetFocustonextControl(true) is really new to me but i thought there had to be something like that available.

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Sorry. I'm being a little stupid. i tried putting this in my subclass



Imports Infragistics

Imports Infragistics.Shared

Imports System.Windows.Forms



Public Class uWingrid

Inherits Infragistics.Win.UltraWinGrid.UltraGrid



Public Sub New()





Me.DisplayLayout.CaptionVisible = Win.DefaultableBoolean.False

Me.DisplayLayout.GroupByBox.Hidden = True

Me.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.FixedAddRowOnBottom

Me.DisplayLayout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.[True]

Me.DisplayLayout.Override.AllowRowSummaries = Infragistics.Win.UltraWinGrid.AllowRowSummaries.[False]

Me.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.[True]





End Sub

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

If e.KeyCode = Keys.E AndAlso e.Control Then

SetFocusToNextControl(True)

End If

MyBase.OnKeyDown(e)

End Sub



Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)

Me.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ActivateCell)

Me.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)



MyBase.OnEnter(e)

End Sub





End Class





The two sub don't seem to be event handlers and they don't appear to be being called.



If I have a form with 13 ultragrids, where would I put the subs ? Or f I wanted this behavior for a single grid? It looks like the code should be in a subclass, but I think I'm missing something about subclassing the grid ....?



I guess my brain isn't working today.

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
My apologies. I should have studied your excellent Ultragrid sample app before posting. I am going to study that, fix my subclass and try it again. I think I am starting to understand.



Thanks for the sample !



Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Charles.

SetFocustonextControl(true) is an UltraGrid method, so it will work fine inside an inherited UltraGrid. But then, you want to use Ctrl+Tab to exit the UltraGrid, which I agree is the easier thing for the user to understand, but I wasn't able to catch the keydown Ctrl+Tab from inside the UltraGrid.

In order to do that, I used my BaseForm and added the following code:

    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
                Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
        End Select

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

This worked fine for me, since all forms will tab to next control once the user types Ctrl+Tab.

Regarding the Subs, they are overriding the grid's OnKeyDown (which we don't need anymore since we are testing the ProcessCmdKey in our base form) and OnEnter subs. That is why we call the MyBase.OnEnter(e) (remember DODEFAULT()? Smile)

Thanks for the question, I wanted to write these features for myself as well. BigGrin

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
By the way, I have moved the OnEnter code to the OnGotFocus:

    Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
        Me.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ActivateCell)
        Me.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)

        MyBase.OnGotFocus(e)
    End Sub


Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Hi Ivan



I've been working a lot using your ultraWingrid subclassing example.



First, in order to exit the grid using Ctrl - Tab :



If e.KeyCode = Windows.Forms.Keys.Tab AndAlso e.Control Then

SetFocusToNextControl(True)

End If



If e.KeyCode = Windows.Forms.Keys.Tab AndAlso e.Control AndAlso e.Shift Then



SetFocusToNextControl(False)

End If



If e.KeyCode = windows.Forms.Keys.Delete andalso e.Control then

Me.currentActiveRow.Delete()

End If

MyBase.OnKeyDown(e)




But the weird thing I have discovered is that if you use a SF TabOrderController on the form the tab in the grid will move to the next control (just as ctrl-tab does in the example above) and not tab you through the grid and into add record at the end.



I've made minor mods to your sample to demonstrate both of these things. As delivered, you'll see tabbing from country into the grid and then tabbing moves through the grid until you exit with either Ctrl-Tab or Ctrl-Shift-Tab.



But now drop a SF TabOrderController on the form, set the properties for the three controls and notice tabbing when in the grid moves your to postal code.



Obviously, what we need is a way to tell the TabOrderController to ignore the Tab if the container is an ultrawingrid.



Any ideas?





Attachments
UltraGridSample-CRHMod.zip (160 views, 142.00 KB)
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Charles.

I have been fighting the UltraGrid for days now! w00t

Getting it to do exactly what I want has been a challenge, but so far I am managing to do it. "Someone" has always told me how working with grids was a pain in the neck...

I will have a look at your sample and see if I can come back with some idea. Wink

Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Here you are, Charles.

Basicaly, I dropped a GroupBox on the form and moved the grid inside it. Then I rearranged the form Tab order, and set the GroupBox "TabOrder on TabOrderController1" to 2, or whatever gets in the middle of the other 2 controls before and afterhand. Next, I added code to the GroupBox_Enter event to move the focus to the grid:

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                                Handles GroupBox1.Enter
        '-- move focus to grid
        Me.grdCustomers.Focus()
    End Sub

And, for the Grid "TabOrder on TabOrderController1", I set -1, so it will tab inside it freely.

Hope it helps. Wink

Attachments
UltraGridSample-CHRMod.zip (173 views, 143.00 KB)
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search