dowdrake1
2016-11-14T18:22:19Z
This post includes two code snippets to improve user experience when editing text in an iGrid6 grid with control version greater or equal to 6.0.33.

The first snippet makes it easier for the user to enter edit mode by simply clicking on the cell.

Private Sub gridReportProjects_Click(ByVal lRow As Long, ByVal lCol As Long)
    MakeEditable lCol
End Sub

Private Sub MakeEditable(lCol As Long)
    Dim g As iGrid600_10Tec.iGrid
    If lCol = 3 Then
        Set g = gridReportProjects.Object
        g.RequestEditCurCell
        g.TextEditSelStart = g.TextEditSelLength
        g.TextEditSelLength = 0
    End If
End Sub

The second snippet helps with the editing process in two ways:
1. The Shift+Spacebar key combination, which users expect to simply insert a space character is defined in all versions of Access to toggle between the current field and the form. If this combination is accidentally pressed, the user is unceremoniously exited from edit mode. This code prevents the default behavior and inserts a space character. For the code to work, it is necessary to set "KeyPreview" to True for the form containing the iGrid control.
2. When text is selected in the grid control, typing a character performs a text replacement as expected, but the Delete key does nothing by default. This code makes it so the Delete key deletes the selected text as expected. If no text is selected, the character after the cursor is deleted.

Edit: The delete code only seems to be necessary for Office 2003. In Office 2007 and above, the default delete key behavior is as expected.
If you are developing for 2007 or above, I would recommend deleting the ElseIf clause

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim g As iGrid600_10Tec.iGrid
    Dim cursorPos As Long
    Dim curText As String
    Dim selLength As Long
    Set g = Me.gridReportProjects.Object
    If Screen.ActiveControl.name = "gridReportProjects" And g.IsEditing Then
        If KeyCode = 32 And Shift = 1 Then ' Handle shift + spacebar
            KeyCode = -1
            cursorPos = g.TextEditSelStart
            curText = g.TextEditText
            g.TextEditText = Left(curText, cursorPos) & " " & Right(curText, Len(curText) - cursorPos)
            g.TextEditSelStart = cursorPos + 1
        ElseIf KeyCode = 46 Then ' Handle delete key
            cursorPos = g.TextEditSelStart
            curText = g.TextEditText
            selLength = g.TextEditSelLength
            If selLength > 0 Then
                g.TextEditText = Left(curText, cursorPos) & Right(curText, Len(curText) - cursorPos - selLength)
            ElseIf cursorPos < Len(curText) Then
                g.TextEditText = Left(curText, cursorPos) & Right(curText, Len(curText) - cursorPos - 1)
            End If
            g.TextEditSelStart = cursorPos
        End If
    End If
    Set g = Nothing
End Sub