chris farrow wrote:
Hello all,
I have a grid that resizes a column when the value in that column gets changed. Without some special workarounds, I get infinite recursion. I've identified the problem. I'm using AutoSizeColumn after a cell change, and this posts an EVT_GRID_CMD_CELL_CHANGE event. Could someone explain the reason for this behavior and perhaps suggest a way to change it?
AutoSizeColumn doesn't actually send the event, but it does call HideCellEditControl and SaveEditControlValue which will send the event if the editor exists and the value is changed. So what is happening is that the editor is in the normal process of being hidden and the value saved when it sends the first event. Your handler then calls AutoSizeColumn which thinks that the value still needs to be saved, which then causes the event to be sent again...
You can work around this in a couple ways. First is to set a flag in the first event before you call AutoSizeColumn, and then when the event arrives again check that flag and return immediately if it is set. Then when AutoSizeColumn returns reset the flag. The other way that would probably work is to not call AutoSizeColumn directly from the handler, but use wx.CallAfter to call it later. Then by the time it is called the cell editor will be hidden and the value saved and it won't try to do it again.
ยทยทยท
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!