issue on Grid behavior

Hello Robin and all. My grid maintains a sqlite table. I have a issue about it.

For example, I have a grid with two fields in which the first must take a not null value.

I do a check for each field so if there is an error (in this case the field null) it is indicated by a

messagebox and any other selected cell is bypassed (veto); and in practice remains the cursor to the cell with the wrong value.

My idea is this: make the field checks in the function associated with event wx.grid.EVT_GRID_EDITOR_HIDDEN:

def OnGridEditorHidden(self,evt):

value = self.textCtrl.GetValue()

if self.ctrField(evt.Row,evt.Col,value) == False:

self.flgerr = ‘s’

self.rowErr = evt.Row

self.colErr = evt.Col

if wx.Platform == ‘WXMSW’\

or wx.Platform == ‘WXMAC’:

wx.CallAfter(self.setCellError,self.rowErr ,self.colErr)

wx.CallAfter(wx.MessageBox,self.message, “ERRORE”, style=wx.OK|wx.ICON_ERROR)

wx.CallAfter(self.enableCellEditControl)

else:

self.setCellError(self.rowErr ,self.colErr)

wx.MessageBox(self.message, “ERRORE”, style=wx.OK|wx.ICON_ERROR)

wx.CallLater(300,self.enableCellEditControl)

return

the function bound to the event EXT GRID CELL SELECT is:

def OnGridSelectCell(self,evt):

if self.flgerr == ‘s’:

self.flgerr = ‘n’

evt.Veto()

return

The user selects the first field (not null), do not type anything then select with the mouse

the second cell, at this point is activated before the editorHidden event on cell(0,0), after is activated the CellSelect event on cell(0,1) but is not allowed. So far it works. But if I move from the first cell on the second with tab press( wx.grid.Grid.MoveCursorRight) it is activated before the GridSelectCell event on cell (0.1), after is activated the GridEditorHidden event on cell (0.0). This seems like a reverse of the previous behavior or wrong? How can I fix this?

For now I tested only on Ubuntu, but soon I’ll do it on MS Windows.

Thanks in advance.

···


Fabio Spadaro
www.fabiospadaro.com

I'm not sure I fully understand your description of the problem, but I think it might be better to do value validation in the EVT_GRID_CELL_CHANGE event as shown in the GridSimple sample in the demo.

BTW, in 2.9 there is a EVT_GRID_CELL_CHANGING event that can be Veto()'d to prevent a bad value being written to the grid.

···

On 5/10/11 1:34 PM, Fabio Spadaro wrote:

The user selects the first field (not null), do not type anything then
select with the mouse
the second cell, at this point is activated before the editorHidden
event on cell(0,0), after is activated the CellSelect event on cell(0,1)
but is not allowed. So far it works. But if I move from the first cell
on the second with tab press( wx.grid.Grid.MoveCursorRight) it is
activated before the GridSelectCell event on cell (0.1), after is
activated the GridEditorHidden event on cell (0.0). This seems like a
reverse of the previous behavior or wrong? How can I fix this?
For now I tested only on Ubuntu, but soon I'll do it on MS Windows.

--
Robin Dunn
Software Craftsman