I have a grid where in certain scenarios, after user input, the cursor needs to remain in the cell. I was just using MoveCursorUp after the EVT_GRID_CELL_CHANGED event to return the cursor to the previous position. Nonetheless, this does not work for the first row.
I ended up doing this:
import wx import wx.grid class GridFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent) self.initialize() def initialize(self): # Create a wxGrid object self.grid = wx.grid.Grid(self, size=(420,700)) self.grid.CreateGrid(5, 5) self.Show() self.Bind(wx.grid.EVT_GRID_CELL_CHANGED, self.onCellChange) def onCellChange(self, event) -> bool: ''' Detects the change on a cell ''' #hacky thing below wx.CallLater(10,self.grid.MoveCursorUp,False) if __name__ == '__main__': app = wx.App(0) frame = GridFrame(None) app.MainLoop()
In this way, using CallLater, it works. But this feels like a complete hack and I guess that there must be a proper way to do this. I suspect there is another event that was cancelling the effect of MoveCursorUp and with CallLater, it is executed after this “mysterious” event. Does someone have any ideas?
Thanks for your help