I'm working on a grid within a dialog, and would like a user's Enter keypress when editing one of the cell values to act as a confirmation of their input - i.e. to stop the edit. The grid uses a number of the wxWidgets cell editors, and I've already added some new behaviour for wxKeyEvents by pushing additional event handlers for both the grid and the different cell editors. These additional event handlers handle key down events only and Skip() for any keycodes they don't care about. What I haven't been able to do, though, is find an event corresponding to an Enter keypress in a cell editor.
The Enter is probably being taken by the dialog and used as a navigation key. (Default behavior is to activate the dialog's default button when enter is pressed.)
ยทยทยท
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Peter Gibbons wrote:
> Could someone tell me what I'm missing here?
>
> I'm working on a grid within a dialog, and would like a user's Enter
> keypress when editing one of the cell values to act as a confirmation of
> their input - i.e. to stop the edit. The grid uses a number of the
> wxWidgets cell editors, and I've already added some new behaviour for
> wxKeyEvents by pushing additional event handlers for both the grid and
> the different cell editors. These additional event handlers handle key
> down events only and Skip() for any keycodes they don't care about. What
> I haven't been able to do, though, is find an event corresponding to an
> Enter keypress in a cell editor.
The Enter is probably being taken by the dialog and used as a navigation
key. (Default behavior is to activate the dialog's default button when
enter is pressed.)
Yep, hitting Enter in a grid cell editor was causing the focus to change to the
next control in the dialog after the grid. Thing is, I couldn't see how the
Enter keypress wouldn't appear as, say, a keydown event in any of the dialog,
grid, or grid cell editor (as do other keypresses in the grid cell editor).
Whatever event corresponded to the Enter press never made it to the keydown
event handlers I added to any of these.
In the end, I got around this by using EVT_CHAR_HOOK() in the wxDialog instance
itself, looking for a WXK_RETURN event, and then adding new handling for this
event if the grid had the required state (i.e. grid has focus, grid cell is
being edited, etc.) Not sure if this is the best approach, but it works