Someone wrote in November 2006:
hello i’m going crazy trying to make this bloody grid show it’s new
data, it refuses to show it’s new data even on forcerefresh
self.RosterStaffGrid.ClearGrid
()for memeber in Staff: Phone = str(memeber[0]) Name = memeber[1] Group = memeber[2] if Group == self.parent.GetPageText([self.id](http://self.id)).split(': ')[0]: self.RosterStaffGrid.table.data.append
([Phone,Name,‘’])
print self.RosterStaffGrid.table.data
self.RosterStaffGrid.ForceRefresh()
As you’re using a custom TableBase, you have to tell the UI that the
data has
changed, by sending some event, whose name I do not remember at the
moment. Have
a look at the wxPython demo, there is at least one grid demo from
which you can
copy the necessary parts.yeah i thought thats what ForceRefresh did?
To which Robin Dunn responded:
If you’re adding new data then you need to tell the grid that there are
new rows by sending it a GridTableMessage. See GridCustTable.py in the
demo.
Oh, brother. I just dragged myself through the same swamp and eventually found this post in the archives after driving myself crazy trying to get a grid to refresh itself after appending rows.
Here’s the necessary code:
msg = wx.grid.GridTableMessage(wx.grid.GridTableMessage(self,
wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, 1))
self.GetView().ProcessTableMessage(msg)
And my additional notes on this: (I don’t mean to be too boisterous, but I can’t help mentioning these)
First, it seems superfluous to send this “extra” notification when we’ve already called grid.AppendRows(). What use is it to have the grid still have no idea that rows have been appended even after its AppendRows() method has been called, until it specifically receives additional notification? However, I understand this is in the hands of wxWidgets, and not its Python wrapper.
I do realize that in order to maintain the important separation of model and view, some message passing etc. is always going to be necessary. But to have the grid look the other way, even though it had to approve the append before it could occur, until it is told twice, seems ridiculous. Am I missing something in the works?
Second, there seems to be no permutation, subset, or reasonable superset of the string ‘GridTableMessage’ showing up anywhere in the wxPython documentation (i mean specifically in the file wx.chm, 2.8.4). Nor does it turn up (unless I’m mistaken) in wxPython In Action.
Third – as if there were some sort of conspiracy to prevent access to the answer to this presumably common pitfall – when you attempt to search in the wxPython demos (2.8.4) for ‘gridtablemessage’, first the code for GridCustTable.py is not in the Code tab of the appropriate demo where it would be expected. Instead it’s in a page linked from the Overview tab. In addition, when you initiate a text search (via keyboard) for, say, ‘gridtablemessage’, the demo window forces the focus back to the Code window, preventing the search from doing anything. I suppose this could be applauded because it effectively forces the reader to read the code (though oddly located) more thoroughly in order to come up with the needed lines.
I love wxPython! But this is about the hardest I’ve had to work for an arcane answer to a common pitfall in a long while.