grid cell editing and enter key (problem with navigation/focus)

hello

There's a grid and bunch of other controls in a dialog. When I hit enter to apply changes in a cell, the focus is set to next control. I must use mouse to get back to the grid to make it handle the GRID_CELL_CHANGE event.

This doesn't happen if a frame is used instead of dialog. How can I use enter key when editing cells?

Related (if not the exactly same) problems must have already been solved here, but i just can't find or recognize those threads...

I'm stuck and using wx 2.5.3.1 on Windows 2000.
Thank you in advance!

···

--
Jussi Oksanen

# ---------------------------------------
import wx
import wx.grid

# instead of updating cell content button gets focus when
# hitting enter after editing cell

class MyDialog(wx.Dialog):
     def __init__(self, *args, **kwds):
         wx.Dialog.__init__(self, None, -1, "My problem", size=(350, 140))
         self.grid = wx.grid.Grid(self, -1)
         self.button = wx.Button(self, -1, "Why do I get the focus?")
         self.grid.CreateGrid(2, 3)
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(self.grid, 1, wx.EXPAND)
         sizer.Add(self.button, 0, wx.FIXED_MINSIZE)
         self.SetAutoLayout(True)
         self.SetSizer(sizer)
         self.Layout()

if __name__ == '__main__':
     app = wx.PySimpleApp()
     dlg = MyDialog()
     dlg.Show(True)
     app.MainLoop()

Jussi Oksanen wrote:

hello

There's a grid and bunch of other controls in a dialog. When I hit enter to apply changes in a cell, the focus is set to next control. I must use mouse to get back to the grid to make it handle the GRID_CELL_CHANGE event.

This doesn't happen if a frame is used instead of dialog. How can I use enter key when editing cells?

One way to do it is to use a custom GridCellEditor class that uses the wx.TE_PROCESS_ENTER style when creating the textctrl.

Another way is to set the style from a EVT_GRID_EDITOR_CREATED handler.

griddlg.py (1018 Bytes)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!