Imran
  • Imran
  • Member Topic Starter
2021-09-02T18:38:40Z
Any how-to's or advice on how to configure i-Grid so that the user can move through the cells using the arrow keys while they are in edit mode?
Basically, users are asking for the same experience they see in Excel.
Thanks
Igor/10Tec
2021-09-03T13:43:56Z
Try to use the TextEditKeyDown/TextEditKeyUp for this. If you detect a cursor movement key in one of these events, save the edit with the CommitEditCurCell method of iGrid and move to the corresponding new cell according to your logic with the help of the SetCurCell method. An alternative way to save edit and move to the next cell is to imitate this by sending the corresponding keys with the SendKeys statement in VB/VBA.
Imran
  • Imran
  • Member Topic Starter
2021-09-03T16:28:21Z
This is what I did, seems somewhat inefficient but it seems to work! Was more code than I was expecting. Let me know if you have any advice or if I missed anything.


Private Sub moGrid_TextEditKeyUp( _
    ByVal lRow As Long, _
    ByVal lCol As Long, _
    ByVal KeyCode As Integer, _
    ByVal Shift As Integer _
)
    Dim lNewRow As Long
    Dim lNewCol As Long
    
    lNewRow = lRow
    lNewCol = lCol
    
   
    'Check for each of the 4 arrow keys and update the row/col by adding or subtracting
    'Also check to see if we are at the edge of the grid and essentially ignore the key press
    Select Case KeyCode
        Case vbKeyUp
            If lNewRow > 1 Then
                lNewRow = lNewRow - 1
            End If
        Case vbKeyDown
            If lNewRow < moGrid.RowCount Then
                lNewRow = lNewRow + 1
            End If
        Case vbKeyLeft
            If lNewCol > 1 Then
                lNewCol = lNewCol - 1
            End If
        Case vbKeyRight
            If lNewCol < moGrid.ColCount Then
                lNewCol = lNewCol + 1
            End If
    End Select
    
    If lNewRow <> lRow Or lNewCol <> lCol Then
        'Commit the current cell edit
        Call moGrid.CommitEditCurCell
        'Move to the new cell
        Call moGrid.SetCurCell(lNewRow, lNewCol)
    End If

End Sub
Igor/10Tec
2021-09-06T14:49:56Z
The part related to iGrid has the minimal size. This is a good usage of iGrid members.

Your logic that finds the next cell is also clear. I would not call it inefficient though it looks long 🙂