Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
615
Programming The KeyDown Event in UltraGrid
posted

I am using Visual Studio 2008, VB.NET, Build 2059, and Windows XP.  I have a question about programming the KeyDown event in the UltraGrid so that it behaves like MS-Excel.  I want UltraGrid to go into Edit Mode when the user starts typing (similar to Microsoft Excel and the native .NET DataGridView control.  Here's my current KeyDown event:

            Select Case e.KeyCode
                Case Keys.Tab
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.NextCell, False, False)
                    e.Handled = True
                Case Keys.Enter
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.NextRow, False, False)
                    e.Handled = True
                Case Keys.Up
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.AboveCell, False, False)
                    e.Handled = True
                Case Keys.Down
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.BelowCell, False, False)
                    e.Handled = True
                Case Keys.PageDown
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.PageDownCell, False, False)
                    e.Handled = True
                Case Keys.PageUp
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.PageUpCell, False, False)
                    e.Handled = True
                Case Keys.Home
                    UltraGrid1.Selected.Cells.Clear()
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.FirstCellInRow, False, False)
                    If UltraGrid1.ActiveCell.Selected = False Then UltraGrid1.PerformAction(UltraGridAction.ToggleCellSel)
                Case Keys.End
                    UltraGrid1.Selected.Cells.Clear()
                    UltraGrid1.PerformAction(UltraGridAction.ExitEditMode, False, False)
                    UltraGrid1.PerformAction(UltraGridAction.LastCellInRow, False, False)
                    If UltraGrid1.ActiveCell.Selected = False Then UltraGrid1.PerformAction(UltraGridAction.ToggleCellSel)
                Case Else
                    If UltraGrid1.ActiveCell IsNot Nothing AndAlso (Not UltraGrid1.ActiveCell.IsInEditMode) Then
                        UltraGrid1.PerformAction(UltraGridAction.EnterEditMode, False, False)
                    End If
            End Select

    Please look at the code in the CASE ELSE section.  Two problems.  First, how do I program it so that it ignores keys such as the Function Keys, BackSpace, other control keys etc.?  Second, there is a timing problem with this code.  When I type the letter "M", the first time I press the "M" key, it is lost while it is going into Edit Mode.  Then I have to press "M" a second time to actually see it show up.

     How can I modify the KeyDown event to handle these two issues?