Getting a wxGrid to use the latest table size

I have a grid that uses a custom table derived from PyGridTableBase (wxPython 2.8, Python 2.6, Windows XP). After I call SetTable(table, True), everything is fine and the data is displayed correctly. At a later time though, I do an operation that will update the table data, which should cause the grid to have more or fewer rows. The problem is, the grid never tries to read the column and row count from the table at any time after the initial SetTable call. I have tried reading the docs, and also the following corrective measures:

    * grid.ForceRefresh - No effect
    * SetTable(table, True) - Crash

Any Ideas?

Ralph

Ralph Nichols wrote:

I have a grid that uses a custom table derived from PyGridTableBase (wxPython 2.8, Python 2.6, Windows XP). After I call SetTable(table, True), everything is fine and the data is displayed correctly. At a later time though, I do an operation that will update the table data, which should cause the grid to have more or fewer rows. The problem is, the grid never tries to read the column and row count from the table at any time after the initial SetTable call. I have tried reading the docs, and also the following corrective measures:

   * grid.ForceRefresh - No effect
   * SetTable(table, True) - Crash

Any Ideas?

Your table needs to send messages to the view (the grid) that informs it of rows or columns being added or removed. See GridCustTable.py in hte demo. There are also some samples in the wiki.

···

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

Ralph Nichols wrote:

I have a grid that uses a custom table derived from PyGridTableBase
(wxPython 2.8, Python 2.6, Windows XP). After I call SetTable(table,
True), everything is fine and the data is displayed correctly. At a
later time though, I do an operation that will update the table data,
which should cause the grid to have more or fewer rows. The
problem is,
the grid never tries to read the column and row count from
the table at
any time after the initial SetTable call. I have tried reading the
docs, and also the following corrective measures:

    * grid.ForceRefresh - No effect
    * SetTable(table, True) - Crash

You need to do the following, where self is your Grid -

    msg = wx.grid.GridTableMessage(self.tablebase,
        wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, no_rows)
    self.ProcessTableMessage(msg)

    msg = wx.grid.GridTableMessage(self.tablebase,
        wx.grid.GRIDTABLE_NOTIFY_ROWS_INSERTED, pos, no_rows)
    self.ProcessTableMessage(msg)

    msg = wx.grid.GridTableMessage(self.tablebase,
        wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, pos, no_rows)
    self.ProcessTableMessage(msg)

For some reason these are not mentioned in the wxWidgets docs, but there are
examples in the demo - have a look at GridCustTable.py.

HTH

Frank Millman