Hi Leandro,
I bumped into a couple of additional issues that I was able to fix, so I thought I'd pass the changes on:
1) Pressing ESC in a cell will insert a box character.
2) Starting typing in a cell will select the inserted character, so subsequent typing will remove the character you were expecting to start your cell value with. e.g. quickly typing "test" will result in the cell text being "est"
3) Pressing Left/Right arrow keys will stop editing a cell when the user likely just wants to move the caret.
4) Pressing the Delete key does nothing. It would be nice if it would edit the cell (if allowed) and clear the contents.
To address the above, I suggest the following changes:
1) Remove Text1_GotFocus
2) Change the vbKeyLeft and vbKeyRight tests in Text1_KeyDown to prevent moving off the cell when there is a selection or when the caret isn't at the beginning or end of the text:
3) Prevent non-printable characters from being inserted into the TextBox (e.g. Escape), add the following code to UserControl_KeyPress right after the test for vbKeyBack:Code:Case vbKeyRight: If Text1.SelStart = Len(Text1.Text) Then If Text1.SelLength = 0 Then mPT.X = mPT.X + 1: bUpdate = True Case vbKeyLeft: If Text1.SelStart = 0 Then If Text1.SelLength = 0 Then mPT.X = mPT.X - 1: bUpdate = True
4) Allow DELETE key to delete contents on edit. Add the following to UserControl_KeyDown in the Select Case Keycode test block:Code:If KeyAscii > 0 And KeyAscii < 32 Then Exit Sub
And Change the UserControl_KeyPress code ater the CellStartEdit call to this:Code:Case vbKeyDelete UserControl_KeyPress -1 ' Delete contents on edit
Code:Select Case KeyAscii Case Is > 0 ' Insert typed character and move caret to end of text Text1.Text = Chr(KeyAscii) Text1.SelStart = Len(Text1.Text) Case -1 ' Delete contents Text1.Text = "" End Select




Reply With Quote